mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 09:57:51 +02:00
Merge pull request #7090 from ZappoMan/fixOctreeBag
move back to unordered_set so that OctreeElementBag will handle uniqueness
This commit is contained in:
commit
1e29faf365
2 changed files with 17 additions and 13 deletions
|
@ -16,26 +16,25 @@ void OctreeElementBag::deleteAll() {
|
|||
_bagElements = Bag();
|
||||
}
|
||||
|
||||
/// does the bag contain elements?
|
||||
/// if all of the contained elements are expired, they will not report as empty, and
|
||||
/// a single last item will be returned by extract as a null pointer
|
||||
bool OctreeElementBag::isEmpty() {
|
||||
// Pop all expired front elements
|
||||
while (!_bagElements.empty() && _bagElements.front().expired()) {
|
||||
_bagElements.pop();
|
||||
}
|
||||
|
||||
return _bagElements.empty();
|
||||
}
|
||||
|
||||
void OctreeElementBag::insert(OctreeElementPointer element) {
|
||||
_bagElements.push(element);
|
||||
_bagElements[element.get()] = element;
|
||||
}
|
||||
|
||||
OctreeElementPointer OctreeElementBag::extract() {
|
||||
OctreeElementPointer result;
|
||||
|
||||
// Find the first element still alive
|
||||
while (!result && !_bagElements.empty()) {
|
||||
result = _bagElements.front().lock(); // Grab head's shared_ptr
|
||||
_bagElements.pop();
|
||||
Bag::iterator it = _bagElements.begin();
|
||||
while (it != _bagElements.end() && !result) {
|
||||
result = it->second.lock();
|
||||
it = _bagElements.erase(it);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -16,17 +16,22 @@
|
|||
#ifndef hifi_OctreeElementBag_h
|
||||
#define hifi_OctreeElementBag_h
|
||||
|
||||
#include <queue>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "OctreeElement.h"
|
||||
|
||||
class OctreeElementBag {
|
||||
using Bag = std::queue<OctreeElementWeakPointer>;
|
||||
using Bag = std::unordered_map<OctreeElement*, OctreeElementWeakPointer>;
|
||||
|
||||
public:
|
||||
void insert(OctreeElementPointer element); // put a element into the bag
|
||||
OctreeElementPointer extract(); // pull a element out of the bag (could come in any order)
|
||||
bool isEmpty();
|
||||
|
||||
OctreeElementPointer extract(); /// pull a element out of the bag (could come in any order) and if all of the
|
||||
/// elements have expired, a single null pointer will be returned
|
||||
|
||||
bool isEmpty(); /// does the bag contain elements,
|
||||
/// if all of the contained elements are expired, they will not report as empty, and
|
||||
/// a single last item will be returned by extract as a null pointer
|
||||
|
||||
void deleteAll();
|
||||
|
||||
|
|
Loading…
Reference in a new issue