aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-06-28 20:48:47 +0000
committerMike Buland <eichlan@xagasoft.com>2009-06-28 20:48:47 +0000
commit4556c5f625ed143a2334acc26505b658b719b451 (patch)
treea3b5b7c9aac69317207eb3fb3a1c7f8e6a7662d8
parent75e487d82390580614b6a36f642b14f5860f1d98 (diff)
downloadlibbu++-4556c5f625ed143a2334acc26505b658b719b451.tar.gz
libbu++-4556c5f625ed143a2334acc26505b658b719b451.tar.bz2
libbu++-4556c5f625ed143a2334acc26505b658b719b451.tar.xz
libbu++-4556c5f625ed143a2334acc26505b658b719b451.zip
Added the Bu::ListHash class, it's a really simple wrapper for Bu::Hash that
puts all of the values in a Bu::List assosiated with the key. When you insert, it will append to the list at that key, and create a list if it needs to. When erasing, getting, etc, you operate on the whole list, not just one element.
-rw-r--r--src/listhash.cpp0
-rw-r--r--src/listhash.h47
2 files changed, 47 insertions, 0 deletions
diff --git a/src/listhash.cpp b/src/listhash.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/listhash.cpp
diff --git a/src/listhash.h b/src/listhash.h
new file mode 100644
index 0000000..73aa3f8
--- /dev/null
+++ b/src/listhash.h
@@ -0,0 +1,47 @@
1#ifndef BU_LIST_HASH_H
2#define BU_LIST_HASH_H
3
4#include "bu/hash.h"
5#include "bu/list.h"
6
7namespace Bu
8{
9 template<typename key, typename value, typename sizecalc = __calcNextTSize_fast, typename keyalloc = std::allocator<key>, typename valuealloc = std::allocator<Bu::List<value> >, typename challoc = std::allocator<uint32_t> >
10 class ListHash : public Hash<key, Bu::List<value>, sizecalc, keyalloc, valuealloc, challoc>
11 {
12 typedef Hash<key, Bu::List<value>, sizecalc, keyalloc, valuealloc, challoc> ParentType;
13 public:
14 ListHash()
15 {
16 }
17
18 ListHash( const ListHash &src ) :
19 ParentType( src )
20 {
21 }
22
23 virtual ~ListHash()
24 {
25 }
26
27 ListHash &operator=( const ListHash &src )
28 {
29 *dynamic_cast<ParentType *>(this) =
30 dynamic_cast<ParentType &>(src);
31 }
32
33 virtual void insert( const key &k, const value &v )
34 {
35 if( !has( k ) )
36 {
37 ParentType::insert( k, List<value>() );
38 }
39 get( k ).append( v );
40 }
41
42 private:
43 };
44
45};
46
47#endif