include/am-hashmap.h
changeset 10 0ac292cc1467
parent 9 4cd655ff4c2c
child 14 4ae6d413d3be
     1.1 --- a/include/am-hashmap.h	Sat Aug 24 02:36:11 2013 -0700
     1.2 +++ b/include/am-hashmap.h	Mon Aug 26 20:41:58 2013 -0700
     1.3 @@ -60,12 +60,28 @@
     1.4      Entry()
     1.5      {
     1.6      }
     1.7 +    Entry(Moveable<Entry> other)
     1.8 +      : key(Moveable<K>(other->key)),
     1.9 +        value(Moveable<V>(other->value))
    1.10 +    {
    1.11 +    }
    1.12  
    1.13      Entry(const K &aKey, const V &aValue)
    1.14       : key(aKey),
    1.15         value(aValue)
    1.16 -    {
    1.17 -    }
    1.18 +    { }
    1.19 +    Entry(const K &aKey, Moveable<V> aValue)
    1.20 +     : key(aKey),
    1.21 +       value(aValue)
    1.22 +    { }
    1.23 +    Entry(Moveable<K> aKey, const V &aValue)
    1.24 +     : key(aKey),
    1.25 +       value(aValue)
    1.26 +    { }
    1.27 +    Entry(Moveable<K> aKey, Moveable<V> aValue)
    1.28 +     : key(aKey),
    1.29 +       value(aValue)
    1.30 +    { }
    1.31    };
    1.32  
    1.33    struct Policy
    1.34 @@ -98,6 +114,7 @@
    1.35  
    1.36    typedef typename Internal::Result Result;
    1.37    typedef typename Internal::Insert Insert;
    1.38 +  typedef typename Internal::iterator iterator;
    1.39  
    1.40    template <typename Lookup>
    1.41    Result find(const Lookup &key) {
    1.42 @@ -123,6 +140,15 @@
    1.43    bool add(Insert &i, const K &key, const V &value) {
    1.44      return table_.add(i, Entry(key, value));
    1.45    }
    1.46 +  bool add(Insert &i, Moveable<K> key, const V &value) {
    1.47 +    return table_.add(i, Entry(key, value));
    1.48 +  }
    1.49 +  bool add(Insert &i, const K &key, Moveable<V> value) {
    1.50 +    return table_.add(i, Entry(key, value));
    1.51 +  }
    1.52 +  bool add(Insert &i, Moveable<K> key, Moveable<V> value) {
    1.53 +    return table_.add(i, Entry(key, value));
    1.54 +  }
    1.55  
    1.56    // This can be used to avoid compiler constructed temporaries, since AMTL
    1.57    // does not yet support move semantics. If you use this, the key and value
    1.58 @@ -131,10 +157,18 @@
    1.59      return table_.add(i);
    1.60    }
    1.61  
    1.62 +  iterator iter() {
    1.63 +    return iterator(&table_);
    1.64 +  }
    1.65 +
    1.66    void clear() {
    1.67      table_.clear();
    1.68    }
    1.69  
    1.70 +  size_t elements() const {
    1.71 +    return table_.elements();
    1.72 +  }
    1.73 +
    1.74    size_t estimateMemoryUse() const {
    1.75      return table_.estimateMemoryUse();
    1.76    }
    1.77 @@ -143,6 +177,17 @@
    1.78    Internal table_;
    1.79  };
    1.80  
    1.81 +template <typename T>
    1.82 +struct PointerPolicy
    1.83 +{
    1.84 +  static inline uint32_t hash(T *p) {
    1.85 +    return HashPointer(p);
    1.86 +  }
    1.87 +  static inline bool matches(T *p1, T *p2) {
    1.88 +    return p1 == p2;
    1.89 +  }
    1.90 +};
    1.91 +
    1.92  }
    1.93  
    1.94  #endif // _include_amtl_hashmap_h_