mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 04:57:58 +02:00
added contains() and remove() methods
This commit is contained in:
parent
2f3a7f8ea8
commit
24501e5c68
2 changed files with 38 additions and 0 deletions
|
@ -82,3 +82,39 @@ VoxelNode* VoxelNodeBag::extract() {
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VoxelNodeBag::contains(VoxelNode* node) {
|
||||||
|
for (int i = 0; i < _elementsInUse; i++) {
|
||||||
|
// just compare the pointers... that's good enough
|
||||||
|
if (_bagElements[i] == node) {
|
||||||
|
return true; // exit early!!
|
||||||
|
}
|
||||||
|
// if we're past where it should be, then it's not here!
|
||||||
|
if (_bagElements[i] > node) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if we made it through the entire bag, it's not here!
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VoxelNodeBag::remove(VoxelNode* node) {
|
||||||
|
int foundAt = -1;
|
||||||
|
for (int i = 0; i < _elementsInUse; i++) {
|
||||||
|
// just compare the pointers... that's good enough
|
||||||
|
if (_bagElements[i] == node) {
|
||||||
|
foundAt = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// if we're past where it should be, then it's not here!
|
||||||
|
if (_bagElements[i] > node) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if we found it, then we need to remove it....
|
||||||
|
if (foundAt != -1) {
|
||||||
|
memmove(&_bagElements[foundAt], &_bagElements[foundAt + 1], (_elementsInUse - foundAt) * sizeof(VoxelNode*));
|
||||||
|
_elementsInUse--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,8 @@ public:
|
||||||
|
|
||||||
void insert(VoxelNode* node); // put a node into the bag
|
void insert(VoxelNode* node); // put a node into the bag
|
||||||
VoxelNode* extract(); // pull a node out of the bag (could come in any order)
|
VoxelNode* extract(); // pull a node out of the bag (could come in any order)
|
||||||
|
bool contains(VoxelNode* node); // is this node in the bag?
|
||||||
|
void remove(VoxelNode* node); // remove a specific item from the bag
|
||||||
|
|
||||||
bool isEmpty() const { return (_elementsInUse == 0); };
|
bool isEmpty() const { return (_elementsInUse == 0); };
|
||||||
int count() const { return _elementsInUse; };
|
int count() const { return _elementsInUse; };
|
||||||
|
|
Loading…
Reference in a new issue