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_MAP_H 00021 #define VEE_HASH_MAP_H 00022 00023 #include <map> 00024 00025 template <typename key, typename content, unsigned SIZE = 256> 00026 class VEE_HashMap 00027 { 00028 public: 00029 00030 typedef std::map<key, content> container; 00031 typedef typename container::iterator citerator; 00032 00033 00034 VEE_HashMap() {} 00035 ~VEE_HashMap() {} 00036 00037 void clear() { for(unsigned i = 0; i < SIZE; i++) m_hash[i].clear(); } 00038 00039 inline unsigned keyToHashIndex(key k) { return ((unsigned) k) & (SIZE - 1); } 00040 00041 inline content & operator[] (key k) { return m_hash[keyToHashIndex(k)][k]; } 00042 00043 content * find(key k) 00044 { 00045 container & item = m_hash[keyToHashIndex(k)]; 00046 00047 citerator it = item.find(k); 00048 00049 return (it != item.end()) ? & (*it).second : 0; 00050 } 00051 00052 void erase(key k) 00053 { 00054 container & item = m_hash[keyToHashIndex(k)]; 00055 00056 citerator it = item.find(k); 00057 00058 if(it != item.end()) 00059 item.erase(it); 00060 } 00061 00062 protected: 00063 00064 container m_hash[SIZE]; 00065 }; 00066 00067 #endif