77namespace kf
88{
99 // /////////////////////////////////////////////////////////////////////////////////////////////////
10- // LinkedTreeMap - map container for NT kernel with predictable iteration order, inspired by https://docs.oracle.com/javase/8/docs/api/java/util/LinkedHashMap.html
10+ // LinkedTreeMap - map container for NT kernel with predictable iteration order,
11+ // inspired by https://docs.oracle.com/javase/8/docs/api/java/util/LinkedHashMap.html
1112
1213 template <class K , class V , POOL_TYPE poolType, class LessComparer =std::less<K>>
1314 class LinkedTreeMap
1415 {
1516 public:
16- LinkedTreeMap ()
17- {
18- }
17+ LinkedTreeMap () noexcept = default ;
18+ LinkedTreeMap (_Inout_ LinkedTreeMap&& another) noexcept = default ;
19+ LinkedTreeMap& operator =(_Inout_ LinkedTreeMap&& another) noexcept = default ;
1920
20- LinkedTreeMap (_Inout_ LinkedTreeMap&& another) : m_table(std::move(another.m_table))
21- {
22- }
21+ LinkedTreeMap (const LinkedTreeMap&) = delete ;
22+ LinkedTreeMap& operator =(const LinkedTreeMap&) = delete ;
2323
2424 ~LinkedTreeMap ()
2525 {
@@ -45,14 +45,10 @@ namespace kf
4545 NTSTATUS status = m_table.insertElement (std::move (node));
4646 if (!NT_SUCCESS (status))
4747 {
48- value = std::move (node.m_value );
4948 return status;
5049 }
5150
52- auto insertedValue = get (key);
53- ASSERT (insertedValue);
54-
55- Node* newNode = CONTAINING_RECORD (insertedValue, Node, m_value);
51+ Node* newNode = m_table.lookupElement (Node::fromKey (key));
5652 ASSERT (newNode);
5753
5854 m_links.addLast (*newNode);
@@ -79,12 +75,14 @@ namespace kf
7975 V* getByIndex (const ULONG index)
8076 {
8177 ULONG currentIndex = 0 ;
82- auto it = m_links. iterator ();
83- while (it. hasNext ())
78+
79+ for ( auto it = m_links. iterator (); it. hasNext (); )
8480 {
81+ auto node = it.next ();
82+
8583 if (currentIndex == index)
8684 {
87- return &it. next () ->m_value ;
85+ return &node ->m_value ;
8886 }
8987
9088 ++currentIndex;
@@ -121,30 +119,16 @@ namespace kf
121119
122120 bool remove (const K& key)
123121 {
124- auto value = get ( key);
125- Node* node = CONTAINING_RECORD (value, Node, m_value);
126- m_links. remove (*node);
127- return m_table. deleteElement ( Node::fromKey (key)) ;
128- }
122+ auto node = m_table. lookupElement ( Node::fromKey ( key) );
123+ if ( node == nullptr )
124+ {
125+ return false ;
126+ }
129127
130- bool removeByObject (const V* value)
131- {
132- Node* node = CONTAINING_RECORD (value, Node, m_value);
133128 m_links.remove (*node);
134129 return m_table.deleteElement (*node);
135130 }
136131
137- LinkedTreeMap& operator =(_Inout_ LinkedTreeMap&& another)
138- {
139- m_links = std::move (another.m_links );
140- m_table = std::move (another.m_table );
141- return *this ;
142- }
143-
144- private:
145- LinkedTreeMap (const LinkedTreeMap&);
146- LinkedTreeMap& operator =(const LinkedTreeMap&);
147-
148132 private:
149133 struct Node
150134 {
@@ -157,9 +141,7 @@ namespace kf
157141 {
158142 }
159143
160- Node (Node&& another) : m_key(std::move(another.m_key)), m_value(std::move(another.m_value)), m_listEntry(std::move(another.m_listEntry))
161- {
162- }
144+ Node (Node&& another) noexcept = default ;
163145
164146 bool operator <(const Node& another) const
165147 {
@@ -169,13 +151,11 @@ namespace kf
169151
170152 K m_key;
171153 V m_value;
172-
173154 DoubleLinkedListEntry m_listEntry;
174155 };
175156
176157 private:
177158 GenericTableAvl<Node, poolType> m_table;
178-
179159 DoubleLinkedList<Node, &Node::m_listEntry> m_links;
180160 };
181161}
0 commit comments