Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

shashtbl.hpp

Go to the documentation of this file.
00001 // +-------------------------------------------------------------------------+
00002 // |               I__n__t__e__L__i__b           0.6.10 development          |
00003 // | Copyright (c) Andrey Vikt. Stolyarov <crocodil_AT_croco.net> 2000-2007. |
00004 // |                                                                         |
00005 // | This is free software. The library part is available under              |
00006 // |                               GNU LESSER GENERAL PUBLIC LICENSE v.2.1.  |
00007 // | GNU LGPL v2.1 is found in docs/gnu_gpl2.txt,  or at  http://www.gnu.org |
00008 // |     Please see also docs/readme.txt and visit http://www.intelib.org    |
00009 // |                                                                         |
00010 // | !!! THERE IS NO WARRANTY OF ANY KIND, NEITHER EXPRESSED NOR IMPLIED !!! |
00011 // +-------------------------------------------------------------------------+
00012 
00013 
00014 
00015 
00027 #ifndef INTELIB_SHASHTBL_HPP_SENTRY
00028 #define INTELIB_SHASHTBL_HPP_SENTRY
00029 
00030 #include "sexpress.hpp"
00031 #include "iexcept.hpp"
00032 #include "gensref.hpp"
00033 
00035 typedef unsigned long intelib_hash_t;
00036 
00038 intelib_hash_t UniversalHash(intelib_hash_t l);
00040 intelib_hash_t LispHash(const SReference &ref);
00041 
00043 typedef bool (*SEqualityPredicate) (SReference, SReference);
00045 bool SExprsAreEq(SReference l1, SReference l2);
00047 bool SExprsAreEql(SReference l1, SReference l2);
00049 bool SExprsAreEqual(SReference l1, SReference l2);
00050 
00051 
00053 
00056 class SExpressionHashTable : public SExpression {
00057     unsigned long dim;
00058     SReference *table; 
00059     SEqualityPredicate comp;
00060     unsigned long itemcount;
00061     long lastfoundpos;
00062 public:
00064     static IntelibTypeId TypeId;
00065 
00067 
00070     static SLabel EmptySlotMark; 
00071 
00073 
00076     SExpressionHashTable(SEqualityPredicate eqp = 0); 
00077 protected:
00078     SExpressionHashTable(const IntelibTypeId &id, 
00079                          SEqualityPredicate eqp = 0); 
00080     ~SExpressionHashTable();
00081     
00082 public:
00083 
00084 #if INTELIB_TEXT_REPRESENTATIONS == 1
00085     virtual class SString TextRepresentation() const;
00086 #endif
00087 
00088     virtual SExpression* Clone() const;
00089     
00091 
00093     void AddItem(SReference key, SReference val);
00094 
00096 
00100     bool SafeAddItem(SReference key, SReference val);
00101 
00103 
00107     SReference FindItem(SReference key, 
00108                 const SReference &defval = EmptySlotMark) const; 
00109 
00111 
00119     SReference& GetItemPosition(SReference key);
00120 
00122 
00125     bool RemoveItem(SReference key);
00126 
00128 
00129     long Count() const { return itemcount; }
00130 
00132 
00133     void Clear();
00134 
00136     class Iterator {
00137         SReference *tbl;
00138         int idx;
00139         int lim;
00140     public:
00142         Iterator(const SExpressionHashTable &tbl);
00144 
00150         SReference& GetNext();        
00151     };
00152 
00153     friend class Iterator::Iterator;
00154   
00155 private:
00156     void DoRemoveItem(long pos);
00157     void ResizeTable();
00158     void HandleLastFoundPos() const;
00159 
00160 };    
00161 
00163 class IntelibX_not_a_hash_table : public IntelibX {
00164 public:
00165     IntelibX_not_a_hash_table(SReference a_param);
00166 };
00167 
00169 typedef GenericSReference<SExpressionHashTable,IntelibX_not_a_hash_table>
00170 SHashTableRef;
00171 
00173 
00177 class SHashTable : public SHashTableRef {
00178 public:
00179     SHashTable(SEqualityPredicate pred = SExprsAreEqual)
00180         : SHashTableRef(new SExpressionHashTable(pred)) {}
00181 };
00182 
00184 class IntelibX_hash_table_too_big : public IntelibX {
00185 public:
00186     IntelibX_hash_table_too_big(SReference a_param);
00187 };
00188 
00189 #endif // sentry

Generated on Tue Dec 18 00:39:45 2007 for InteLib by  doxygen 1.4.1