pointer_hash.cpp

Go to the documentation of this file.
00001 #ifndef POINTER_HASH_IMPLEMENTATION
00002 #define POINTER_HASH_IMPLEMENTATION
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : pointer_hash                                                      *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2001-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "byte_hasher.h"
00019 #include "hash_table.cpp"
00020 #include "pointer_hash.h"
00021 
00022 #include <basis/set.cpp>
00023 
00024 template <class contents>
00025 pointer_hash<contents>::pointer_hash(int max_bits)
00026 : hash_table<void *, contents>(rotating_byte_hasher(), max_bits),
00027   _ids(new pointer_set)
00028 {}
00029 
00030 template <class contents>
00031 pointer_hash<contents>::~pointer_hash()
00032 { WHACK(_ids); }
00033 
00034 template <class contents>
00035 const pointer_set &pointer_hash<contents>::ids() const { return *_ids; }
00036 
00037 template <class contents>
00038 void pointer_hash<contents>::ids(pointer_set &ids) const { ids = *_ids; }
00039 
00040 template <class contents>
00041 outcome pointer_hash<contents>::add(void *key, contents *to_store)
00042 {
00043   _ids->add(key);
00044   return hash_table<void *, contents>::add(key, to_store);
00045 }
00046 
00047 template <class contents>
00048 contents *pointer_hash<contents>::acquire(void *key)
00049 {
00050   _ids->remove(key);
00051   return hash_table<void *, contents>::acquire(key);
00052 }
00053 
00054 template <class contents>
00055 bool pointer_hash<contents>::zap(void *key)
00056 {
00057   _ids->remove(key);
00058   return hash_table<void *, contents>::zap(key);
00059 }
00060 
00061 template <class contents>
00062 void pointer_hash<contents>::reset()
00063 {
00064   _ids->clear();
00065   hash_table<void *, contents>::reset();
00066 }
00067 
00068 template <class contents>
00069 void pointer_hash<contents>::apply(apply_function *to_apply, void *data_link)
00070 {
00071   for (int i = 0; i < _ids->elements(); i++) {
00072     void *current = (*_ids)[i];
00073     contents *found = hash_table<void *, contents>::find(current);
00074     if (!found) {
00075       _ids->remove(current);
00076       continue;
00077     }
00078     to_apply(current, *found, data_link);
00079   }
00080 }
00081 
00082 #endif // outer guard.
00083 

Generated on Fri Aug 29 04:28:47 2008 for HOOPLE Libraries by  doxygen 1.5.1