1 /*******************************************************************************
2 
3     Elastic binary tree base class
4 
5     Base class for EBTree32/64/128. Hosts eb_root and the node counter.
6 
7     Copyright:
8         Copyright (c) 2009-2016 dunnhumby Germany GmbH.
9         All rights reserved.
10 
11     License:
12         Boost Software License Version 1.0. See LICENSE_BOOST.txt for details.
13         Alternatively, this file may be distributed under the terms of the Tango
14         3-Clause BSD License (see LICENSE_BSD.txt for details).
15 
16 *******************************************************************************/
17 
18 module ocean.util.container.ebtree.model.IEBTree;
19 
20 
21 import ocean.util.container.ebtree.c.ebtree: eb_root;
22 
23 /******************************************************************************/
24 
25 abstract class IEBTree
26 {
27     import ocean.core.Verify;
28 
29     /***************************************************************************
30 
31         Tree root node.
32 
33     ***************************************************************************/
34 
35     protected eb_root root;
36 
37 
38     /***************************************************************************
39 
40         Number of nodes in the tree.
41 
42     ***************************************************************************/
43 
44     private size_t count;
45 
46 
47     /***************************************************************************
48 
49         Returns:
50             the number of records currently in the tree.
51 
52     ***************************************************************************/
53 
54     public size_t length ( )
55     {
56         return this.count;
57     }
58 
59     /***************************************************************************
60 
61         Removes all values from the tree.
62 
63     ***************************************************************************/
64 
65     public void clear ( )
66     {
67         this.count = 0;
68         this.root  = this.root.init;
69     }
70 
71     /***************************************************************************
72 
73         Increases the record counter by n.
74 
75         Params:
76             n = amount to add to the record counter value
77 
78         Returns:
79             new record counter value
80 
81     ***************************************************************************/
82 
83     protected size_t increaseNodeCount ( size_t n )
84     {
85         return this.count += n;
86     }
87 
88     /***************************************************************************
89 
90         Decreases the record counter by n.
91 
92         Params:
93             n = amount to subtract from the record counter value
94 
95         Returns:
96             new record counter value
97 
98         In:
99             n must be at most the current record counter value.
100 
101     ***************************************************************************/
102 
103     protected size_t decreaseNodeCount ( size_t n )
104     {
105         verify (this.count >= n);
106         return this.count -= n;
107     }
108 }