From 0fa0e0752a28eeb43195f2288c018d5c0b24520b Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 17 Jan 2011 14:57:37 +0200 Subject: old water removed, some fixes here and there --- src/utility.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/utility.h') 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 +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::Iterator i = m_list.begin(); + Value value = *i; + m_map.remove(value); + m_list.erase(i); + return value; + } + +private: + core::map m_map; + core::list m_list; +}; #endif -- cgit v1.2.3