Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

NVHash Class Reference

#include <NVHash.h>

Inheritance diagram for NVHash:

NVlist NVcontainer NVActiveDB List of all members.

Public Member Functions

 NVHash ()
 NVHash (const char *dbname, unsigned long hashsz=97, int flags=0)
void open (const char *dbname, unsigned long hashsz=97, int flags=0)
unsigned long gethashsz (void)
void clear (void)
int is_empty (void)
void add (unsigned long h, const char *data, size_t szdata)
void print (std::ostream &os)

Protected Member Functions

void make_current (void)
int sis_empty (void)
void sclear (void)
void sadd (unsigned long h, const char *data, size_t szdata)
void sprint (std::ostream &os)

Protected Attributes

nvoff_thashtab
unsigned long hashsz

Detailed Description

Author:
Thomas Gschwind
Bug:
Documentation is missing.

Definition at line 15 of file NVHash.h.


Constructor & Destructor Documentation

NVHash::NVHash  )  [inline]
 

Definition at line 29 of file NVHash.h.

00029                  :NVlist() {
00030         } NVHash(const char *dbname, unsigned long hashsz = 97, int flags =

NVHash::NVHash const char *  dbname,
unsigned long  hashsz = 97,
int  flags = 0
 

Definition at line 56 of file NVHash.cc.

References open().

00057 :NVlist()
00058 {
00059         open(dbname, hashsz, flags);
00060 }


Member Function Documentation

void NVHash::add unsigned long  h,
const char *  data,
size_t  szdata
 

Definition at line 105 of file NVHash.cc.

References NVcontainer::lock(), and sadd().

Referenced by NVActiveDB::add(), and NVActiveDB::sset().

00106 {
00107         lock(ExclLock);
00108         sadd(h, data, szdata);
00109         lock(UnLock);
00110 }

void NVHash::clear void   ) 
 

Reimplemented in NVActiveDB.

Definition at line 89 of file NVHash.cc.

References NVcontainer::lock(), and sclear().

Referenced by NVActiveDB::clear().

00090 {
00091         lock(ExclLock);
00092         sclear();
00093         lock(UnLock);
00094 }

unsigned long NVHash::gethashsz void   )  [inline]
 

Returns the size of the has-table.

Returns:
size of the hash table

Definition at line 46 of file NVHash.h.

References hashsz.

00046                                       {
00047                 // No lock and make_current invocation necessary, since 
00048                 // the hash-size must not change
00049                 return hashsz;
00050         }

int NVHash::is_empty void   ) 
 

Reimplemented in NVActiveDB.

Definition at line 96 of file NVHash.cc.

References NVcontainer::lock(), and sis_empty().

Referenced by NVActiveDB::is_empty().

00097 {
00098         int r;
00099         lock(ShrdLock);
00100         r = sis_empty();
00101         lock(UnLock);
00102         return r;
00103 }

void NVHash::make_current void   )  [protected, virtual]
 

Reimplemented from NVcontainer.

Definition at line 10 of file NVHash.cc.

References NVcontainer::getdata(), hashsz, hashtab, NVcontainer::is_current(), NVcontainer::make_current(), and nvoff_t.

00011 {
00012         nvoff_t hdata;
00013 
00014         if (mem_p && is_current())
00015                 return;
00016 
00017         NVlist::make_current();
00018         if ((hdata = getdata()) == 0) {
00019                 hashtab = NULL;
00020                 hashsz = 0;
00021         } else {
00022                 hashtab =
00023                     (nvoff_t *) (mem_p + hdata + sizeof(unsigned long));
00024                 hashsz = *(unsigned long *) (mem_p + hdata);
00025         }
00026 }

void NVHash::open const char *  dbname,
unsigned long  hashsz = 97,
int  flags = 0
 

Open an NVHash object.

Parameters:
dbname Name of the file, where the hash-table is stored.
hashsz Size of the hash-table, if a new one is created.
flags Ignored at the moment.

Definition at line 62 of file NVHash.cc.

References hashsz, hashtab, NVcontainer::lock(), NVcontainer::nvalloc(), nvoff_t, NVcontainer::open(), and NVcontainer::setdata().

Referenced by NVHash(), and NVActiveDB::open().

00063 {
00064         NVlist::open(dbname, flags);
00065         if (!hashtab) {
00066                 lock(ExclLock);
00067                 if (!hashtab) {
00068                         nvoff_t ht =
00069                             nvalloc(sizeof(unsigned long) +
00070                                     nhashsz * sizeof(nvoff_t));
00071                         unsigned long i;
00072                         setdata(ht);
00073 
00074                         hashsz = (*(unsigned long *) (mem_p + ht)) =
00075                             nhashsz;
00076                         hashtab =
00077                             (nvoff_t *) (mem_p + ht +
00078                                          sizeof(unsigned long));
00079 
00080                         for (i = 0; i < hashsz; i++)
00081                                 hashtab[i] = 0;
00082                 }
00083                 lock(UnLock);
00084         }
00085         // The hashsz and hashtab variables will be updated at the next
00086         // make_current method-invocation
00087 }

void NVHash::print std::ostream &  os  ) 
 

Definition at line 112 of file NVHash.cc.

References NVcontainer::lock(), and sprint().

00113 {
00114         lock(ShrdLock);
00115         sprint(os);
00116         lock(UnLock);
00117 }

void NVHash::sadd unsigned long  h,
const char *  data,
size_t  szdata
[protected]
 

Definition at line 44 of file NVHash.cc.

References hashtab, and NVlist::sprepend().

Referenced by add().

00045 {
00046         NVlist::sprepend((char *) &(hashtab[h]) - mem_p, data, szdata);
00047 }

void NVHash::sclear void   )  [protected]
 

Definition at line 28 of file NVHash.cc.

References hashsz, hashtab, and NVlist::sclear().

Referenced by clear().

00029 {
00030         unsigned long i;
00031         for (i = 0; i < hashsz; i++)
00032                 NVlist::sclear((char *) &(hashtab[i]) - mem_p);
00033 }

int NVHash::sis_empty void   )  [protected]
 

Definition at line 35 of file NVHash.cc.

References hashsz, and hashtab.

Referenced by is_empty().

00036 {
00037         unsigned long i;
00038         for (i = 0; i < hashsz; i++)
00039                 if (hashtab[i])
00040                         return 0;
00041         return 1;
00042 }

void NVHash::sprint std::ostream &  os  )  [protected]
 

Definition at line 49 of file NVHash.cc.

References hashsz, hashtab, and NVlist::sprint().

Referenced by print().

00050 {
00051         unsigned long i;
00052         for (i = 0; i < hashsz; i++)
00053                 NVlist::sprint((char *) &(hashtab[i]) - mem_p, os);
00054 }


Member Data Documentation

unsigned long NVHash::hashsz [protected]
 

Definition at line 21 of file NVHash.h.

Referenced by NVActiveDB_Iter::_skip_nulls(), NVHashIter::first(), gethashsz(), make_current(), NVHashIter::next(), NVActiveDB_Iter::next(), NVActiveDB_Iter::NVActiveDB_Iter(), open(), sclear(), sis_empty(), and sprint().

nvoff_t* NVHash::hashtab [protected]
 

Definition at line 20 of file NVHash.h.

Referenced by NVActiveDB_Iter::_skip_nulls(), NVHashIter::first(), make_current(), NVHashIter::next(), open(), sadd(), sclear(), sis_empty(), and sprint().


The documentation for this class was generated from the following files:
Generated on Sun Oct 24 21:08:24 2004 for NewsCache by doxygen 1.3.6-20040222