X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FAtomicHashMap.h;h=f0b04a56366c2b1a3dbf3cf9f6a458fa494e6787;hb=e872b4400ebf7d68f9b0fca1b3b851556d22513a;hp=5de4f503527f9f7e2ae1f25e9bd1e65b204c3782;hpb=dc6cfb04ebf1ab5917cef0136f9fb342dfc421fd;p=folly.git diff --git a/folly/AtomicHashMap.h b/folly/AtomicHashMap.h index 5de4f503..f0b04a56 100644 --- a/folly/AtomicHashMap.h +++ b/folly/AtomicHashMap.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 Facebook, Inc. + * Copyright 2015 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -90,11 +90,11 @@ #include #include -#include "folly/AtomicHashArray.h" -#include "folly/Foreach.h" -#include "folly/Hash.h" -#include "folly/Likely.h" -#include "folly/ThreadCachedInt.h" +#include +#include +#include +#include +#include namespace folly { @@ -135,7 +135,9 @@ namespace folly { * make_pair everywhere), and providing both can lead to some gross * template error messages. * - * - Not Allocator-aware. + * - The Allocator must not be stateful (a new instance will be spun up for + * each allocation), and its allocate() method must take a raw number of + * bytes. * * - KeyT must be a 32 bit or 64 bit atomic integer type, and you must * define special 'locked' and 'empty' key values in the ctor @@ -143,10 +145,6 @@ namespace folly { * - We don't take the Hash function object as an instance in the * constructor. * - * - We don't take a Compare template parameter (since our keys must - * be integers, and the underlying hash array here uses atomic - * compare-and-swap instructions, we only allow normal integer - * comparisons). */ // Thrown when insertion fails due to running out of space for @@ -157,16 +155,17 @@ struct AtomicHashMapFullError : std::runtime_error { {} }; -template +template class AtomicHashMap : boost::noncopyable { - typedef AtomicHashArray SubMap; + typedef AtomicHashArray SubMap; public: typedef KeyT key_type; typedef ValueT mapped_type; typedef std::pair value_type; typedef HashFcn hasher; - typedef std::equal_to key_equal; + typedef EqualFcn key_equal; typedef value_type* pointer; typedef value_type& reference; typedef const value_type& const_reference; @@ -204,7 +203,7 @@ class AtomicHashMap : boost::noncopyable { } } - key_equal key_eq() const { return key_eq(); } + key_equal key_eq() const { return key_equal(); } hasher hash_function() const { return hasher(); } // TODO: emplace() support would be nice. @@ -319,17 +318,21 @@ class AtomicHashMap : boost::noncopyable { } iterator begin() { - return iterator(this, 0, + iterator it(this, 0, subMaps_[0].load(std::memory_order_relaxed)->begin()); - } - - iterator end() { - return iterator(); + it.checkAdvanceToNextSubmap(); + return it; } const_iterator begin() const { - return const_iterator(this, 0, + const_iterator it(this, 0, subMaps_[0].load(std::memory_order_relaxed)->begin()); + it.checkAdvanceToNextSubmap(); + return it; + } + + iterator end() { + return iterator(); } const_iterator end() const { @@ -411,6 +414,6 @@ class AtomicHashMap : boost::noncopyable { } // namespace folly -#include "AtomicHashMap-inl.h" +#include #endif // FOLLY_ATOMICHASHMAP_H_