Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

hashtable.h

Go to the documentation of this file.
00001 //****************************************************
00002 //  April, 1993, University of Illinois
00003 // Copyright (C) 1993, 1994 Tianlin Wang
00004 /* Copyright (C) 1994-2003 Matvec Development Team. 
00005 
00006   This program is free software; you can redistribute it and/or
00007   modify it under the terms of the GNU Library General Public
00008   License as published by the Free Software Foundation; either
00009   version 2 of the License, or (at your option) any later version.
00010   
00011   This program is distributed in the hope that it will be useful,
00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014   Library General Public License for more details.
00015     
00016   You should have received a copy of the GNU Library General Public
00017   License along with this library; if not, write to the Free
00018   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00019   MA 02111-1307, USA 
00020 */
00021 
00022 #ifndef HashTable_H
00023 #define HashTable_H
00024 
00025 #include <cstdlib>
00026 #include <iostream>
00027 
00028 namespace matvec {
00029 class HashTable;
00030 /*!
00031    \class HashNode  hashtable.h
00032    \brief a node for the hashtable
00033 
00034    \sa HashTable
00035 */
00036 
00037 class HashNode {
00038    friend  class HashTable;
00039    private:
00040       size_t   datasize;
00041       char     *data;
00042       unsigned id;
00043       void     copyfrom(const HashNode& A);
00044 
00045    public:
00046       HashNode(void);
00047       HashNode(const HashNode& A){data = 0; datasize = 0; copyfrom(A);}
00048       ~HashNode(void){release();}
00049 
00050       const    HashNode& operator=(const HashNode& A);
00051       int      equal(const char *v);
00052       void     insert(const char *v,const size_t ds,const unsigned idno);
00053       void     resize(const size_t s);
00054       unsigned id_no(void) {return id;}
00055       void     release(void);
00056 };
00057 
00058 HashNode* new_HashNode_vec(const unsigned n,const size_t s);
00059 
00060 typedef void (*displaytype)(const void*);
00061 
00062 /*!
00063    \class HashTable  HashTable.h
00064    \brief a hash table
00065 
00066 */
00067 
00068 class HashTable {
00069     public:
00070        enum hashaction {INSERT,GETIDNO};
00071        HashTable(void);
00072        HashTable(const unsigned n, const size_t s);
00073        HashTable(const unsigned n, const char str[]);
00074        HashTable(const HashTable& A){copyfrom(A);}
00075        ~HashTable(void){release();}
00076 
00077        const HashTable& operator=(const HashTable& A);
00078 
00079        HashTable&  resize(const unsigned n, const size_t s);
00080        HashTable&  resize(const unsigned n) {return resize(n,0);}
00081 
00082        unsigned    insert(const void *v); // return its id of v in HashTable
00083        size_t      data_len(void){return datasize;}
00084        unsigned    get_id(const void *v);
00085        unsigned    size(void) const {return act_tablesize;}
00086        void        change_id(const unsigned oldid,const unsigned newid);
00087        void        reorder(void);
00088        void        maxsize(const unsigned ms);
00089        void        release(void);
00090        void        save(const char *fname,
00091                         const int io_mode=std::ios::out); //SDK ios::noreplace is missing 
00092        void        input(const char fname[]);
00093        void        save_to_disk(std::ostream& stream,const int relse=1);
00094        void        input_from_disk(std::istream& stream);
00095        void        display(displaytype dply);
00096        void        copyfrom(const HashTable& A);
00097 
00098        const void* find(const unsigned id) const;
00099 
00100    private:
00101       unsigned  tablesize,ext_tablesize,act_tablesize,datasize, id_changed;
00102       HashNode  **hash_table;
00103       HashNode  *hash_storage;
00104 
00105    protected:
00106       unsigned hash(const char* v, HashTable::hashaction action);
00107 };
00108 
00109 }
00110 #endif

Generated on Thu Jun 16 17:13:44 2005 for Matvec by doxygen1.2.16