mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 03:58:07 +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();
|
_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() {
|
bool OctreeElementBag::isEmpty() {
|
||||||
// Pop all expired front elements
|
|
||||||
while (!_bagElements.empty() && _bagElements.front().expired()) {
|
|
||||||
_bagElements.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
return _bagElements.empty();
|
return _bagElements.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OctreeElementBag::insert(OctreeElementPointer element) {
|
void OctreeElementBag::insert(OctreeElementPointer element) {
|
||||||
_bagElements.push(element);
|
_bagElements[element.get()] = element;
|
||||||
}
|
}
|
||||||
|
|
||||||
OctreeElementPointer OctreeElementBag::extract() {
|
OctreeElementPointer OctreeElementBag::extract() {
|
||||||
OctreeElementPointer result;
|
OctreeElementPointer result;
|
||||||
|
|
||||||
// Find the first element still alive
|
// Find the first element still alive
|
||||||
while (!result && !_bagElements.empty()) {
|
Bag::iterator it = _bagElements.begin();
|
||||||
result = _bagElements.front().lock(); // Grab head's shared_ptr
|
while (it != _bagElements.end() && !result) {
|
||||||
_bagElements.pop();
|
result = it->second.lock();
|
||||||
|
it = _bagElements.erase(it);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,17 +16,22 @@
|
||||||
#ifndef hifi_OctreeElementBag_h
|
#ifndef hifi_OctreeElementBag_h
|
||||||
#define hifi_OctreeElementBag_h
|
#define hifi_OctreeElementBag_h
|
||||||
|
|
||||||
#include <queue>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "OctreeElement.h"
|
#include "OctreeElement.h"
|
||||||
|
|
||||||
class OctreeElementBag {
|
class OctreeElementBag {
|
||||||
using Bag = std::queue<OctreeElementWeakPointer>;
|
using Bag = std::unordered_map<OctreeElement*, OctreeElementWeakPointer>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void insert(OctreeElementPointer element); // put a element into the bag
|
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();
|
void deleteAll();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue