MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / FlatMap

Class FlatMap

tensorflow/core/lib/gtl/flatmap.h:39–388  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37template <typename Key, typename Val, class Hash = hash<Key>,
38 class Eq = std::equal_to<Key>>
39class FlatMap {
40 private:
41 // Forward declare some internal types needed in public section.
42 struct Bucket;
43
44 // We cannot use std::pair<> since internal representation stores
45 // keys and values in separate arrays, so we make a custom struct
46 // that holds references to the internal key, value elements.
47 //
48 // We define the struct as private ValueType, and typedef it as public
49 // value_type, to work around a gcc bug when compiling the iterators.
50 struct ValueType {
51 typedef Key first_type;
52 typedef Val second_type;
53
54 const Key& first;
55 Val& second;
56 ValueType(const Key& k, Val& v) : first(k), second(v) {}
57 };
58
59 public:
60 typedef Key key_type;
61 typedef Val mapped_type;
62 typedef Hash hasher;
63 typedef Eq key_equal;
64 typedef size_t size_type;
65 typedef ptrdiff_t difference_type;
66 typedef ValueType value_type;
67 typedef value_type* pointer;
68 typedef const value_type* const_pointer;
69 typedef value_type& reference;
70 typedef const value_type& const_reference;
71
72 FlatMap() : FlatMap(1) {}
73
74 explicit FlatMap(size_t N, const Hash& hf = Hash(), const Eq& eq = Eq())
75 : rep_(N, hf, eq) {}
76
77 FlatMap(const FlatMap& src) : rep_(src.rep_) {}
78
79 // Move constructor leaves src in a valid but unspecified state (same as
80 // std::unordered_map).
81 FlatMap(FlatMap&& src) : rep_(std::move(src.rep_)) {}
82
83 template <typename InputIter>
84 FlatMap(InputIter first, InputIter last, size_t N = 1,
85 const Hash& hf = Hash(), const Eq& eq = Eq())
86 : FlatMap(N, hf, eq) {
87 insert(first, last);
88 }
89
90 FlatMap(std::initializer_list<std::pair<const Key, Val>> init, size_t N = 1,
91 const Hash& hf = Hash(), const Eq& eq = Eq())
92 : FlatMap(init.begin(), init.end(), N, hf, eq) {}
93
94 FlatMap& operator=(const FlatMap& src) {
95 rep_.CopyFrom(src.rep_);
96 return *this;

Callers

nothing calls this directly

Calls 6

valMethod · 0.80
MaybeResizeMethod · 0.80
FindOrInsertMethod · 0.80
CopyFromMethod · 0.45
MoveFromMethod · 0.45
FindMethod · 0.45

Tested by

no test coverage detected