• R/O
  • SSH
  • HTTPS

eirrepo: Commit


Commit MetaInfo

Revision153 (tree)
Time2018-11-25 20:02:06
Authorquiret

Log Message

- added RemoveNode methods for eir::Set and eir::Map
- added map-Style functions for eir::Vector

Change Summary

Incremental Difference

--- common/sdk/Map.h (revision 152)
+++ common/sdk/Map.h (revision 153)
@@ -302,6 +302,15 @@
302302 NewNode( this, this->data.avlKeyTree, key, std::move( value ) );
303303 }
304304
305+ // Removes a specific node that was previously found.
306+ // The code must make sure that the node really belongs to this tree.
307+ inline void RemoveNode( Node *theNode )
308+ {
309+ this->data.avlKeyTree.RemoveByNodeFast( &theNode->sortedByKeyNode );
310+
311+ dismantle_node( this, theNode );
312+ }
313+
305314 // Erases any Node by key.
306315 inline void RemoveByKey( const keyType& key )
307316 {
@@ -311,11 +320,9 @@
311320 return;
312321
313322 // Remove it.
314- this->data.avlKeyTree.RemoveByNodeFast( avlExistingNode );
315-
316323 Node *existingNode = AVL_GETITEM( Node, avlExistingNode, sortedByKeyNode );
317324
318- dismantle_node( this, existingNode );
325+ RemoveNode( existingNode );
319326 }
320327
321328 // Clears all keys and values from this Map.
@@ -368,6 +375,7 @@
368375 }
369376
370377 MAKE_SETMAP_ITERATOR( iterator, Map, Node, sortedByKeyNode, data.avlKeyTree, MapAVLTree );
378+ MAKE_SETMAP_ITERATOR( const_iterator, const Map, Node, sortedByKeyNode, data.avlKeyTree, MapAVLTree );
371379
372380 // Walks through all nodes of this tree.
373381 template <typename callbackType>
--- common/sdk/Set.h (revision 152)
+++ common/sdk/Set.h (revision 153)
@@ -297,6 +297,15 @@
297297 NewNode( this, this->data.avlValueTree, std::move( value ) );
298298 }
299299
300+ // Removes a specific node that was previously found.
301+ // The code must make sure that the node really belongs to this tree.
302+ inline void RemoveNode( Node *theNode )
303+ {
304+ this->data.avlValueTree.RemoveByNodeFast( &theNode->sortedByValueNode );
305+
306+ dismantle_node( this, theNode );
307+ }
308+
300309 // Erases any Node by value.
301310 inline void Remove( const valueType& value )
302311 {
@@ -306,11 +315,9 @@
306315 return;
307316
308317 // Remove it.
309- this->data.avlValueTree.RemoveByNodeFast( avlExistingNode );
310-
311318 Node *existingNode = AVL_GETITEM( Node, avlExistingNode, sortedByValueNode );
312319
313- dismantle_node( this, existingNode );
320+ RemoveNode( existingNode );
314321 }
315322
316323 // Clears all values from this Set.
@@ -364,6 +371,8 @@
364371
365372 // Public iterator.
366373 MAKE_SETMAP_ITERATOR( iterator, Set, Node, sortedByValueNode, data.avlValueTree, SetAVLTree );
374+ typedef const Node constNode;
375+ MAKE_SETMAP_ITERATOR( const_iterator, Set, constNode, sortedByValueNode, data.avlValueTree, SetAVLTree );
367376
368377 // Walks through all nodes of this tree.
369378 template <typename callbackType>
--- common/sdk/Vector.h (revision 152)
+++ common/sdk/Vector.h (revision 153)
@@ -955,6 +955,33 @@
955955 }
956956 }
957957
958+ // Returns a reference to a slot on this vector. If indices up to and including this
959+ // slot do not exist, then they are standard-constructed.
960+ // Useful for map-operating-mode.
961+ inline structType& ObtainItem( size_t idx )
962+ {
963+ if ( idx >= this->data.data_count )
964+ {
965+ this->Resize( idx + 1 );
966+ }
967+
968+ return this->data.data_entries[ idx ];
969+ }
970+
971+ // Puts an item into the vector on a certain index. If there is not enough space on
972+ // this vector, then it is resized to fit automatically.
973+ // The new slots that are allocated will all be standard-constructed.
974+ // Useful for map-operating-mode.
975+ inline void SetItem( size_t idx, structType&& item )
976+ {
977+ this->ObtainItem( idx ) = std::move( item );
978+ }
979+
980+ inline void SetItem( size_t idx, const structType& item )
981+ {
982+ this->ObtainItem( idx ) = item;
983+ }
984+
958985 // Removes all items from this array by release the back-end memory.
959986 inline void Clear( void )
960987 {
Show on old repository browser