• R/O
  • SSH
  • HTTPS

eirrepo: Commit


Commit MetaInfo

Revision169 (tree)
Time2018-12-20 02:45:14
Authorquiret

Log Message

- added some more methods to eir::SortedSliceSector

Change Summary

Incremental Difference

--- common/sdk/SortedSliceSector.h (revision 168)
+++ common/sdk/SortedSliceSector.h (revision 169)
@@ -160,6 +160,8 @@
160160
161161 if ( avlBeginMergeWithNode )
162162 {
163+ // TODO: maybe optimize this by doing another maximum-by-criteria scan.
164+
163165 // Need to count in all nodes that actually do meet the criteria, that is by iterating.
164166 avlSliceTree_t::diff_node_iterator crit_iter( avlBeginMergeWithNode );
165167
@@ -308,6 +310,61 @@
308310 return ( this->data.avlSliceTree.GetRootNode() == nullptr );
309311 }
310312
313+ template <typename... removalArgs>
314+ AINLINE void Clear( removalArgs... args )
315+ {
316+ while ( AVLNode *avlCurNode = this->data.avlSliceTree.GetRootNode() )
317+ {
318+ sliceNode *curNode = AVL_GETITEM( sliceNode, avlCurNode, node );
319+
320+ curNode->metaData.Remove( args... );
321+
322+ this->data.avlSliceTree.RemoveByNode( avlCurNode );
323+
324+ eir::dyn_del_struct <sliceNode> ( this->data.allocData, this, curNode );
325+ }
326+ }
327+
328+ AINLINE size_t GetSliceCount( void ) const
329+ {
330+ avlSliceTree_t::diff_node_iterator iter( this->data.avlSliceTree );
331+
332+ size_t count = 0;
333+
334+ while ( !iter.IsEnd() )
335+ {
336+ count++;
337+
338+ iter.Increment();
339+ }
340+
341+ return count;
342+ }
343+
344+ AINLINE sectorSlice_t GetSpan( void ) const
345+ {
346+ AVLNode *avlBegNode = this->data.avlSliceTree.GetSmallestNode();
347+
348+ if ( avlBegNode == nullptr )
349+ {
350+ return sectorSlice_t();
351+ }
352+
353+ sliceNode *begNode = AVL_GETITEM( sliceNode, avlBegNode, node );
354+
355+ numberType rangeMin = begNode->GetNodeSlice().GetSliceStartPoint();
356+
357+ AVLNode *avlEndNode = this->data.avlSliceTree.GetBiggestNode();
358+
359+ assert( avlEndNode != nullptr );
360+
361+ sliceNode *endNode = AVL_GETITEM( sliceNode, avlEndNode, node );
362+
363+ numberType rangeMax = endNode->GetNodeSlice().GetSliceEndPoint();
364+
365+ return sectorSlice_t::fromOffsets( rangeMin, rangeMax );
366+ }
367+
311368 private:
312369 static AINLINE eCompResult _CompareSlices( const sectorSlice_t& leftSlice, const sectorSlice_t& rightSlice, bool doCountInNeighbors )
313370 {
--- unittests/src/sortedslicesector.cpp (revision 168)
+++ unittests/src/sortedslicesector.cpp (revision 169)
@@ -50,6 +50,55 @@
5050 }
5151 printf( "ok.\n" );
5252
53+ printf( "testing sorted-slice-sector clear..." );
54+ {
55+ eir::SortedSliceSector <int, EirHeapAllocator> slices;
56+
57+ assert( slices.IsEmpty() == true );
58+
59+ slices.Insert( { 2, 3 } );
60+
61+ assert( slices.IsEmpty() == false );
62+
63+ slices.Clear();
64+
65+ assert( slices.IsEmpty() == true );
66+ }
67+ printf( "ok.\n" );
68+
69+ printf( "testing sorted-slice-sector count..." );
70+ {
71+ eir::SortedSliceSector <int, EirHeapAllocator> slices;
72+
73+ assert( slices.GetSliceCount() == 0 );
74+
75+ slices.Insert( { 1, 3 } );
76+
77+ assert( slices.GetSliceCount() == 1 );
78+
79+ slices.Insert( { 5, 1 } );
80+
81+ assert( slices.GetSliceCount() == 2 );
82+
83+ slices.Insert( { 4, 1 } );
84+
85+ assert( slices.GetSliceCount() == 1 );
86+ }
87+ printf( "ok.\n" );
88+
89+ printf( "testing sorted-slice-sector span..." );
90+ {
91+ eir::SortedSliceSector <int, EirHeapAllocator> slices;
92+
93+ slices.Insert( { -20, 1 } );
94+ slices.Insert( { 20, 1 } );
95+
96+ sliceOfData <int> spanSlice = slices.GetSpan();
97+
98+ assert( spanSlice.GetSliceStartPoint() == -20 && spanSlice.GetSliceEndPoint() == 20 );
99+ }
100+ printf( "ok.\n" );
101+
53102 printf( "testing sorted-slice-sector for-each..." );
54103 {
55104 eir::SortedSliceSector <int, EirHeapAllocator> slices;
Show on old repository browser