kmail Library API Documentation

kmdict.h

00001 /* simple hash table for kmail.  inspired by QDict
00002  */
00003 
00004 #ifndef __KMDICT
00005 #define __KMDICT
00006 
00007 #include <algorithm>
00008 
00009 namespace KMail {
00010 // List of prime numbers shamelessly stolen from GCC STL
00011 enum { num_primes = 29 };
00012 
00013 static const unsigned long prime_list[ num_primes ] =
00014 {
00015   31ul,        53ul,         97ul,         193ul,       389ul,
00016   769ul,       1543ul,       3079ul,       6151ul,      12289ul,
00017   24593ul,     49157ul,      98317ul,      196613ul,    393241ul,
00018   786433ul,    1572869ul,    3145739ul,    6291469ul,   12582917ul,
00019   25165843ul,  50331653ul,   100663319ul,  201326611ul, 402653189ul,
00020   805306457ul, 1610612741ul, 3221225473ul, 4294967291ul
00021 };
00022 
00023 inline unsigned long nextPrime( unsigned long n )
00024 {
00025   const unsigned long *first = prime_list;
00026   const unsigned long *last = prime_list + num_primes;
00027   const unsigned long *pos = std::lower_bound( first, last, n );
00028   return pos == last ? *( last - 1 ) : *pos;
00029 }
00030 
00031 }
00032 
00033 class KMDictItem
00034 {
00035 public:
00036   long key;
00037   KMDictItem *next;
00038 };
00039 
00040 
00041 class KMDict
00042 {
00043 public:
00045   KMDict(int size = 17);
00046   
00048   ~KMDict();
00049 
00051   void init(int size);
00052   
00054   void clear();
00055   
00057   int size() { return mSize; }
00058   
00060   void replace(long key, KMDictItem *item);
00061  
00063   void insert(long key, KMDictItem *item);
00064  
00066   void remove(long key);
00067   
00069   KMDictItem *find(long key);
00070   
00071 protected:
00073   void removeFollowing(KMDictItem *item, long key);
00074   
00076   int mSize;
00077   
00079   KMDictItem **mVecs;
00080 };
00081 
00082 #endif /* __KMDICT */
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Aug 23 18:21:19 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003