mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 11:17:34 +02:00
use std::unordered_map<> instead of std::unordered_set<>
This commit is contained in:
parent
26ab1bdac4
commit
477dfe1b10
3 changed files with 7 additions and 54 deletions
|
@ -24,17 +24,17 @@ bool OctreeElementBag::isEmpty() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void OctreeElementBag::insert(OctreeElementPointer element) {
|
void OctreeElementBag::insert(OctreeElementPointer element) {
|
||||||
_bagElements.insert(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();
|
||||||
Bag::iterator it = _bagElements.begin();
|
while (it != _bagElements.end() && !result) {
|
||||||
result = (*it).lock(); // Grab head's shared_ptr
|
result = it->second.lock();
|
||||||
_bagElements.erase(it);
|
it = _bagElements.erase(it);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,15 +16,12 @@
|
||||||
#ifndef hifi_OctreeElementBag_h
|
#ifndef hifi_OctreeElementBag_h
|
||||||
#define hifi_OctreeElementBag_h
|
#define hifi_OctreeElementBag_h
|
||||||
|
|
||||||
#include <unordered_set>
|
#include <unordered_map>
|
||||||
#include <shared/WeakPointerHash.h>
|
|
||||||
|
|
||||||
#include "OctreeElement.h"
|
#include "OctreeElement.h"
|
||||||
|
|
||||||
class OctreeElementBag {
|
class OctreeElementBag {
|
||||||
using OctreeElementWeakPointerHash = WeakPointerHash<OctreeElement>;
|
using Bag = std::unordered_map<OctreeElement*, OctreeElementWeakPointer>;
|
||||||
using OctreeElementWeakPointerEqual = WeakPointerEqual<OctreeElement>;
|
|
||||||
using Bag = std::unordered_set<OctreeElementWeakPointer, OctreeElementWeakPointerHash, OctreeElementWeakPointerEqual>;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void insert(OctreeElementPointer element); // put a element into the bag
|
void insert(OctreeElementPointer element); // put a element into the bag
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
//
|
|
||||||
// WeakPointerHash.h
|
|
||||||
// libraries/shared
|
|
||||||
//
|
|
||||||
// Created by Brad Hefta-Gaub on 2/11/2015.
|
|
||||||
// Copyright 2015 High Fidelity, Inc.
|
|
||||||
//
|
|
||||||
// std::hash<> compatible Hash and Equal functions for std::weak_ptr<> classes
|
|
||||||
//
|
|
||||||
// borrowed heavily from:
|
|
||||||
// http://stackoverflow.com/questions/13695640/how-to-make-a-c11-stdunordered-set-of-stdweak-ptr
|
|
||||||
//
|
|
||||||
// warning:
|
|
||||||
// there is some question as to whether or not this hash function is really safe to use because
|
|
||||||
// it doesn't guarentee that the hash for the weak_ptr() is the same for every requested hash
|
|
||||||
// as noted on the link above, this behavior may cause instability or undefined behavior
|
|
||||||
// in some hash users when the weak_ptr<> has expired.
|
|
||||||
//
|
|
||||||
// Distributed under the Apache License, Version 2.0.
|
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef hifi_WeakPointerHash_h
|
|
||||||
#define hifi_WeakPointerHash_h
|
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct WeakPointerHash : public std::unary_function<std::weak_ptr<T>, size_t> {
|
|
||||||
size_t operator()(const std::weak_ptr<T>& weakPointer) {
|
|
||||||
auto sharedPointer = weakPointer.lock();
|
|
||||||
return std::hash<decltype(sharedPointer)>()(sharedPointer);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct WeakPointerEqual : public std::unary_function<std::weak_ptr<T>, bool> {
|
|
||||||
bool operator()(const std::weak_ptr<T>& left, const std::weak_ptr<T>& right) {
|
|
||||||
return !left.owner_before(right) && !right.owner_before(left);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // hifi_WeakPointerHash_h
|
|
Loading…
Reference in a new issue