26 #ifndef Common_BlobHashSet_h
27 #define Common_BlobHashSet_h
31 #include <unordered_set>
43 template <
class TraitsT = BlobHashTraits<> >
44 class BlobHashSet :
public std::unordered_set<Blob, typename TraitsT::hasher,
45 typename TraitsT::key_equal> {
47 typedef std::unordered_set<
Blob,
typename TraitsT::hasher,
48 typename TraitsT::key_equal>
Base;
55 typedef std::pair<iterator, bool>
InsRet;
75 InsRet
insert(
const void *buf,
size_t len) {
105 iterator
find(
const Blob &blob) {
return Base::find(blob); }
113 return Base::find(Blob(s.data(), s.size()));
136 const_cast<const void *&
>(rv.first->start) =
137 m_alloc.dup(rv.first->start, len);
std::string String
A String is simply a typedef to std::string.
std::pair< iterator, bool > InsRet
Base::value_type value_type
A Blob structure holds a data pointer and a size.
BlobHashSet()
Constructor creates an empty set.
InsRet insert(const Blob &blob)
Insert function for a Blob object.
TraitsT::key_allocator key_allocator
InsRet insert_blob(size_t len, InsRet rv)
Helper function to insert a blob; if the blob already exists then a duplicate blob is created and ins...
iterator find(const String &s)
Find function for String objects.
InsRet insert(const String &s)
Insert function for a String object.
BlobHashSet(size_t n_buckets)
Overloaded Constructor creates an empty set with a specified number of buckets.
std::unordered_set< Blob, typename TraitsT::hasher, typename TraitsT::key_equal > Base
Helper structures for BlobHashSet.
InsRet insert(const void *buf, size_t len)
Inserts a new Blob into the set.
A HashSet for storing and looking up blobs efficiently.
key_allocator m_alloc
The key_allocator - i.e.
iterator find(const Blob &blob)
Looks up the blob and returns an iterator to it.
key_allocator & key_alloc()
Returns the allocator; used for testing.