Aegis  4.25.D505
/home/archives/aegis/branch.4/branch.25/delta28933.505/common/symtab.h
Go to the documentation of this file.
00001 //
00002 //      aegis - project change supervisor
00003 //      Copyright (C) 1994, 2002-2008, 2012 Peter Miller.
00004 //
00005 //      This program is free software; you can redistribute it and/or modify
00006 //      it under the terms of the GNU General Public License as published by
00007 //      the Free Software Foundation; either version 3 of the License, or
00008 //      (at your option) any later version.
00009 //
00010 //      This program is distributed in the hope that it will be useful,
00011 //      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 //      GNU General Public License for more details.
00014 //
00015 //      You should have received a copy of the GNU General Public License
00016 //      along with this program. If not, see
00017 //      <http://www.gnu.org/licenses/>.
00018 //
00019 
00020 #ifndef COMMON_SYMTAB_H
00021 #define COMMON_SYMTAB_H
00022 
00023 #include <common/mem.h>
00024 #include <common/nstring.h>
00025 
00026 class string_list_ty; // forward
00027 class nstring_list; // forward
00028 
00040 class symtab_ty
00041 {
00042 public:
00047     ~symtab_ty();
00048 
00057     symtab_ty(int suggested_size = 5);
00058 
00063     size_t size() const { return hash_load; }
00064 
00069     bool empty() const { return (hash_load == 0); }
00070 
00078     void clear(void);
00079 
00095     void *query(string_ty *key) const;
00096 
00111     void *query(const nstring &key) const;
00112 
00124     void *query(const nstring_list &keys) const;
00125 
00141     string_ty *query_fuzzy(string_ty *key) const;
00142 
00156     nstring query_fuzzy(const nstring &key) const;
00157 
00175     void assign(string_ty *key, void *value);
00176 
00193     void assign(const nstring &key, void *value);
00194 
00211     void assign_push(string_ty *key, void *value);
00212 
00228     void assign_push(const nstring &key, void *value);
00229 
00243     void remove(string_ty *key);
00244 
00257     void remove(const nstring &key);
00258 
00272     void dump(const char *caption) const;
00273 
00289     void keys(string_list_ty *result) const;
00290 
00305     void keys(nstring_list &result) const;
00306 
00307     typedef void (*callback_t)(const symtab_ty *stp, const nstring &key,
00308         void *data, void *arg);
00309 
00322     void walk(callback_t func, void *arg) const;
00323 
00324     typedef void (*reaper_t)(void *);
00325 
00331     void set_reap(reaper_t func) { reap = func; }
00332 
00337     bool valid() const;
00338 
00339 private:
00354     void split(void);
00355 
00359     reaper_t reap;
00360 
00361     struct row_t
00362     {
00363         row_t() : data(0), overflow(0) { }
00364         nstring key;
00365         void *data;
00366         row_t *overflow;
00367     };
00368 
00374     row_t **hash_table;
00375 
00380     str_hash_ty hash_modulus;
00381 
00388     str_hash_ty hash_mask;
00389 
00394     str_hash_ty hash_load;
00395 
00399     symtab_ty(const symtab_ty &);
00400 
00404     symtab_ty &operator=(const symtab_ty &);
00405 
00406     friend class symtab_iterator;
00407 };
00408 
00409 symtab_ty *symtab_alloc(int n) DEPRECATED;
00410 void symtab_free(symtab_ty *stp) DEPRECATED;
00411 
00412 void *symtab_query(const symtab_ty *stp, string_ty *key) DEPRECATED;
00413 string_ty *symtab_query_fuzzy(const symtab_ty *stp, string_ty *key) DEPRECATED;
00414 void symtab_assign(symtab_ty *stp, string_ty *key, void *value) DEPRECATED;
00415 void symtab_assign_push(symtab_ty *stp, string_ty *key, void *value) DEPRECATED;
00416 void symtab_delete(symtab_ty *stp, string_ty *key) DEPRECATED;
00417 void symtab_dump(const symtab_ty *stp, const char *caption) DEPRECATED;
00418 void symtab_walk(const symtab_ty *stp, symtab_ty::callback_t func, void *arg)
00419     DEPRECATED;
00420 void symtab_keys(const symtab_ty *stp, string_list_ty *result) DEPRECATED;
00421 
00424 #endif // COMMON_SYMTAB_H
00425 // vim: set ts=8 sw=4 et :