00001 /* -*- C++ -*- */ 00002 00003 /* COPYRIGHT 00004 * 00005 * This file is part of the Visual Effects Engine - VEE 00006 * 00007 * Read the "VEE-LICENSE" file for the license. 00008 * 00009 * Authors & Copyright: 00010 * 00011 * Tommi Ilmonen, Tuukka Heikura, Marko Myllymaa and 00012 * Janne Kontkanen 2001-2004 00013 * 00014 * Additional copyrights: Tekes 2003-2004 00015 * 00016 * firstname.lastname@hut.fi 00017 * 00018 */ 00019 00020 #ifndef VEE_HASH_SET_H 00021 #define VEE_HASH_SET_H 00022 00023 #include <set> 00024 00025 template <typename key, unsigned SIZE = 256> 00026 class VEE_HashSet 00027 { 00028 public: 00029 00030 typedef std::set<key> container; 00031 typedef typename container::iterator citerator; 00032 00033 VEE_HashSet() {} 00034 ~VEE_HashSet() {} 00035 00036 void clear() { for(unsigned i = 0; i < SIZE; i++) m_hash[i].clear(); } 00037 00038 inline unsigned keyToHashIndex(key k) { return ((unsigned) k) & (SIZE - 1); } 00039 00040 void insert(key k) { m_hash[keyToHashIndex(k)].insert(k); } 00041 00042 bool find(key k) 00043 { 00044 container & item = m_hash[keyToHashIndex(k)]; 00045 00046 citerator it = item.find(k); 00047 00048 return it != item.end(); 00049 } 00050 00051 void erase(key k) 00052 { 00053 container & item = m_hash[keyToHashIndex(k)]; 00054 00055 citerator it = item.find(k); 00056 00057 if(it != item.end()) 00058 item.erase(it); 00059 } 00060 00061 protected: 00062 00063 container m_hash[SIZE]; 00064 }; 00065 00066 #endif