File tree Expand file tree Collapse file tree 7 files changed +72
-8
lines changed
BaselineOfContainersAVLTree
Containers-AVL-Tree-Inspector
Containers-AVL-Tree-Tests Expand file tree Collapse file tree 7 files changed +72
-8
lines changed Original file line number Diff line number Diff line change @@ -23,9 +23,8 @@ BaselineOfContainersAVLTree >> baseline: spec [
2323
2424 " Groups"
2525 spec
26- group: ' Core'
27- with: #( 'Containers-AVL-Tree' 'Containers-AVL-Tree-Inspector' ) ;
26+ group: ' Core' with: #( 'Containers-AVL-Tree' 'Containers-AVL-Tree-Inspector' ) ;
2827 group: ' Tests' with: #( 'Containers-AVL-Tree-Tests' ) .
2928
3029 spec group: ' default' with: #( 'Core' 'Tests' ) ]
31- ]
30+ ]
Original file line number Diff line number Diff line change 11Extension { #name : ' CTAVLTree' }
22
33{ #category : ' *Containers-AVL-Tree-Inspector' }
4- CTAVLTree >> inspectorCanvas [
4+ CTAVLTree >> inspectorCanvas: aBuilder [
5+
56 < inspectorPresentationOrder: 90 title: ' AVL' >
6- ^ CTAVLTreeVisualizer new
7- tree: self ;
8- asPresenter
7+ ^ (aBuilder instantiate: SpRoassalInspectorPresenter )
8+ canvas: (CTAVLTreeVisualizer new
9+ tree: self ;
10+ build;
11+ canvas);
12+ yourself
913]
Original file line number Diff line number Diff line change @@ -38,6 +38,16 @@ CTAVLTreeTest >> testAddSingleElement [
3838 self assert: tree height equals: 1
3939]
4040
41+ { #category : ' tests' }
42+ CTAVLTreeTest >> testAllChildren [
43+
44+ | elements |
45+ elements := (1 to: 10000 ) collect: [ :i | Random new nextIntegerBetween: 1 and : 100000000 ].
46+ tree addAll: elements.
47+
48+ self assertCollection: (tree allChildren collect: #contents ) hasSameElements: elements
49+ ]
50+
4151{ #category : ' tests' }
4252CTAVLTreeTest >> testAnySatisfy [
4353
Original file line number Diff line number Diff line change @@ -28,6 +28,12 @@ CTAVLAbstractNode >> balanceFactor [
2828 ^ self subclassResponsibility
2929]
3030
31+ { #category : ' accessing' }
32+ CTAVLAbstractNode >> children [
33+
34+ ^ { }
35+ ]
36+
3137{ #category : ' accessing' }
3238CTAVLAbstractNode >> contents [
3339
@@ -95,6 +101,12 @@ CTAVLAbstractNode >> inOrderDo: aBlock [
95101 ^ self subclassResponsibility
96102]
97103
104+ { #category : ' testing' }
105+ CTAVLAbstractNode >> isBalanced [
106+
107+ ^ false
108+ ]
109+
98110{ #category : ' testing' }
99111CTAVLAbstractNode >> isEmpty [
100112
@@ -107,6 +119,12 @@ CTAVLAbstractNode >> isLeaf [
107119 ^ self subclassResponsibility
108120]
109121
122+ { #category : ' testing' }
123+ CTAVLAbstractNode >> isNilNode [
124+
125+ ^ false
126+ ]
127+
110128{ #category : ' accessing' }
111129CTAVLAbstractNode >> parent [
112130
Original file line number Diff line number Diff line change @@ -102,6 +102,12 @@ CTAVLNilNode >> isLeaf [
102102 ^ false
103103]
104104
105+ { #category : ' testing' }
106+ CTAVLNilNode >> isNilNode [
107+
108+ ^ true
109+ ]
110+
105111{ #category : ' enumerating' }
106112CTAVLNilNode >> postOrderDo: aBlock [
107113
Original file line number Diff line number Diff line change @@ -42,6 +42,12 @@ CTAVLNode >> balanceFactor [
4242 ^ left height - right height
4343]
4444
45+ { #category : ' accessing' }
46+ CTAVLNode >> children [
47+
48+ ^ { left . right }
49+ ]
50+
4551{ #category : ' accessing' }
4652CTAVLNode >> contents [
4753
@@ -137,6 +143,12 @@ CTAVLNode >> initialize [
137143 height := 1
138144]
139145
146+ { #category : ' testing' }
147+ CTAVLNode >> isBalanced [
148+
149+ ^ (left height - right height) abs <= 1
150+ ]
151+
140152{ #category : ' testing' }
141153CTAVLNode >> isEmpty [
142154
@@ -298,7 +310,7 @@ CTAVLNode >> successorOf: anObject [
298310{ #category : ' private' }
299311CTAVLNode >> updateHeight [
300312
301- height := 1 + (left height max: right height)
313+ height := 1 + (left height max: right height)
302314]
303315
304316{ #category : ' private' }
Original file line number Diff line number Diff line change @@ -36,6 +36,21 @@ CTAVLTree >> addAll: aCollection [
3636 ^ aCollection
3737]
3838
39+ { #category : ' accessing' }
40+ CTAVLTree >> allChildren [
41+
42+ | currentNode nodesToVisit children |
43+ children := Set new .
44+ nodesToVisit := LinkedList with: root.
45+
46+ [ nodesToVisit isNotEmpty ] whileTrue: [
47+ currentNode := nodesToVisit removeFirst.
48+ children add: currentNode.
49+ nodesToVisit addAll: (currentNode children reject: #isNilNode ) ].
50+
51+ ^ children
52+ ]
53+
3954{ #category : ' enumerating' }
4055CTAVLTree >> anySatisfy: aBlock [
4156
You can’t perform that action at this time.
0 commit comments