[mathic] 20/62: added draft HashTable.h but it is not functional yet
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Wed Apr 1 11:36:19 UTC 2015
This is an automated email from the git hooks/post-receive script.
dtorrance-guest pushed a commit to branch master
in repository mathic.
commit 1933cd17bf8811c11919bdd6b64797c42912f69c
Author: Mike Stillman <mikestillman1 at gmail.com>
Date: Wed Aug 1 09:26:43 2012 -0400
added draft HashTable.h but it is not functional yet
---
src/mathic/HashTable.cpp | 12 +++++
src/mathic/HashTable.h | 121 +++++++++++++++++++++++++++++++++++++++++++++++
src/test/HashTable.cpp | 7 +++
3 files changed, 140 insertions(+)
diff --git a/src/mathic/HashTable.cpp b/src/mathic/HashTable.cpp
new file mode 100644
index 0000000..f54f8da
--- /dev/null
+++ b/src/mathic/HashTable.cpp
@@ -0,0 +1,12 @@
+#include "stdinc.h"
+#include "HashTable.h"
+
+#include <stdexcept>
+
+namespace mathic {
+
+}
+
+// Local Variables:
+// indent-tabs-mode: nil
+// End:
diff --git a/src/mathic/HashTable.h b/src/mathic/HashTable.h
new file mode 100644
index 0000000..76d6ed6
--- /dev/null
+++ b/src/mathic/HashTable.h
@@ -0,0 +1,121 @@
+// MathicGB copyright 2012 all rights reserved. MathicGB comes with ABSOLUTELY
+// NO WARRANTY and is licensed as GPL v2.0 or later - see LICENSE.txt.
+
+
+// issues:
+// 1. memory management of nodes
+// 2. statistics gathering
+// 3. resizing
+// 4. put ASSERT's in, to check for all manner of contracts
+
+#ifndef MATHIC_HASHTABLE_GUARD
+#define MATHIC_HASHTABLE_GUARD
+
+#include "stdinc.h"
+
+namespace mathic {
+
+ template<class Configuration>
+ class HashTable;
+
+ class BasicHashTableConfiguration {
+ typedef int Key;
+ typedef int Value;
+
+ size_t hash(Key k);
+ bool equals(Key k1, Key k2);
+ bool combine(Value &a, const Value &b);
+ };
+
+ template<class Configuration>
+ class HashTable;
+
+ template<class C>
+ class HashTable {
+ public:
+ typedef C Configuration;
+ typedef void * node;
+
+ // Create a hash table
+ HashTable(Configuration &conf, unsigned int nbits = 10);
+
+ ~HashTable() {}
+
+ // Returns the stored configuration.
+ Configuration& configuration() {return mConf;}
+
+ // Returns the stored configuration.
+ Configuration const& configuration() const {return mConf;}
+
+ // insert the key 'k' into the hash table. If the key is already there,
+ // call C.combine on the old and new values.
+ // If combine returns false, then remove the node from the hash table.
+ // and return std::pair(false, ...)
+ // else return std::pair(true, node in the hash table).
+ std::pair<bool, node *> insert(const Key &k, const Value &v);
+
+ // remove 'p' from the hash table. 'p' itself is not removed???!
+ void remove(node *p);
+
+ const Key &key(node *p) const { return static_cast<Node *>(p)->k; }
+
+ const Value &value(node *p) const { return static_cast<Node *>(p)->v; }
+
+ void reset(); // Major assumption: all nodes have been removed from the table already
+
+ void hardReset(); // Slow, avoid if possible.
+
+ // Returns how many bytes of memory this data structure consumes
+ // not including sizeof(*this).
+ size_t memoryUse() const;
+
+ // Returns a string that describes how this data structure was
+ // configured.
+ std::string name() const;
+
+ private:
+ struct node {
+ Node *next;
+ Key k;
+ Value v;
+ };
+
+
+ size_t mHashMask; // this is the number, in binary: 00001111...1, where
+ // the number of 1's is mLogTableSize
+
+ size_t mTableSize;
+ size_t mLogTableSize; // number of bits in the table: mTableSize should be 2^mLogTableSize
+
+ size_t mNodeCount; // current number of nodes in the hash table
+ size_t mBinCount; // number of nonzero bins
+ size_t mMaxCountBeforeRebuild;
+
+ memt::BufferPool mNodePool;
+ std::vector<node *> mHashTable;
+ Configuration mConf;
+ };
+
+ template<class C>
+ HashTable::HashTable(const Configuration &conf, unsigned int nbits):
+ mLogTableSize(nbits),
+ mTableSize(1 << nbits),
+ mHashMask((1 << nbits) - 1),
+ mNodePool(sizeof(Node)),
+ mConf(conf)
+ {
+ mHashTable.resize(mTableSize);
+ mMaxCountBeforeRebuild = mConf.rebuildThreshold * mTableSize;
+
+ MATHIC_ASSERT(tableIsZero(mHashTable));
+ }
+
+
+
+} // namespace mathic
+
+#endif
+
+// Local Variables:
+// indent-tabs-mode: nil
+// End:
diff --git a/src/test/HashTable.cpp b/src/test/HashTable.cpp
new file mode 100755
index 0000000..c0c723f
--- /dev/null
+++ b/src/test/HashTable.cpp
@@ -0,0 +1,7 @@
+//#include "mathic/HashTable.h"
+#include <gtest/gtest.h>
+
+TEST(HashTable, NoOp) {
+ ASSERT_TRUE(true);
+};
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mathic.git
More information about the debian-science-commits
mailing list