From 4556c5f625ed143a2334acc26505b658b719b451 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 28 Jun 2009 20:48:47 +0000 Subject: 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. --- src/listhash.cpp | 0 src/listhash.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/listhash.cpp create mode 100644 src/listhash.h diff --git a/src/listhash.cpp b/src/listhash.cpp new file mode 100644 index 0000000..e69de29 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 @@ +#ifndef BU_LIST_HASH_H +#define BU_LIST_HASH_H + +#include "bu/hash.h" +#include "bu/list.h" + +namespace Bu +{ + template, typename valuealloc = std::allocator >, typename challoc = std::allocator > + class ListHash : public Hash, sizecalc, keyalloc, valuealloc, challoc> + { + typedef Hash, sizecalc, keyalloc, valuealloc, challoc> ParentType; + public: + ListHash() + { + } + + ListHash( const ListHash &src ) : + ParentType( src ) + { + } + + virtual ~ListHash() + { + } + + ListHash &operator=( const ListHash &src ) + { + *dynamic_cast(this) = + dynamic_cast(src); + } + + virtual void insert( const key &k, const value &v ) + { + if( !has( k ) ) + { + ParentType::insert( k, List() ); + } + get( k ).append( v ); + } + + private: + }; + +}; + +#endif -- cgit v1.2.3