summaryrefslogtreecommitdiff
path: root/src/utility.h
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-01-17 14:57:37 +0200
committerPerttu Ahola <celeron55@gmail.com>2011-01-17 14:57:37 +0200
commit0fa0e0752a28eeb43195f2288c018d5c0b24520b (patch)
tree72c05dc4cd98663d92a6a312c6b8128c18791590 /src/utility.h
parentbd26be262d30eeb0ca818b634891704de4365893 (diff)
downloadminetest-0fa0e0752a28eeb43195f2288c018d5c0b24520b.tar.gz
minetest-0fa0e0752a28eeb43195f2288c018d5c0b24520b.tar.bz2
minetest-0fa0e0752a28eeb43195f2288c018d5c0b24520b.zip
old water removed, some fixes here and there
Diffstat (limited to 'src/utility.h')
-rw-r--r--src/utility.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/utility.h b/src/utility.h
index c4f45ba0f..a38d15f30 100644
--- a/src/utility.h
+++ b/src/utility.h
@@ -1580,6 +1580,47 @@ private:
bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir, f32 range);
+/*
+ Queue with unique values with fast checking of value existence
+*/
+
+template<typename Value>
+class UniqueQueue
+{
+public:
+
+ /*
+ Does nothing if value is already queued.
+ Return value:
+ true: value added
+ false: value already exists
+ */
+ bool push_back(Value value)
+ {
+ // Check if already exists
+ if(m_map.find(value) != NULL)
+ return false;
+
+ // Add
+ m_map.insert(value, 0);
+ m_list.push_back(value);
+
+ return true;
+ }
+
+ void pop_front()
+ {
+ typename core::list<Value>::Iterator i = m_list.begin();
+ Value value = *i;
+ m_map.remove(value);
+ m_list.erase(i);
+ return value;
+ }
+
+private:
+ core::map<Value, u8> m_map;
+ core::list<Value> m_list;
+};
#endif