-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathProgram.cs
More file actions
157 lines (141 loc) · 5.14 KB
/
Program.cs
File metadata and controls
157 lines (141 loc) · 5.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using System;
using System.Collections.Generic;
using FriendlyCSharp.Databases;
namespace BtnEnumerator.Multi.sample
{
public class TestKV : FcsBTreeN<int, uint>
{
protected override bool BtnUpdates(int keyAdd, uint valueAdd, ref uint valueUpdates, object objUpdates)
{
valueUpdates++;
return true;
}
//////////////////////////
protected override int BtnCompares(int keyX, int keyY, object objCmp)
{
// return less < 0, equal = 0, greater > 0
return keyX - keyY;
}
//////////////////////////
public TestKV() : base(2)
{
}
}
class Program
{
static void Main(string[] args)
{
Console.OutputEncoding = System.Text.Encoding.UTF8;
Console.WriteLine(String.Format("BtnEnumerator.Multi.sample, {0}", (IntPtr.Size == 4) ? "32 bit" : "64 bit"));
Console.WriteLine("-----------------------------------");
uint uiCount = 1;
TestKV btnTest = new TestKV();
// Build the tree
btnTest.BtnAdd(20, uiCount);
btnTest.BtnAdd(40, uiCount);
btnTest.BtnAdd(10, uiCount);
btnTest.BtnAdd(30, uiCount);
btnTest.BtnAdd(15, uiCount); //
btnTest.BtnAdd(35, uiCount);
btnTest.BtnAdd(7, uiCount);
btnTest.BtnAdd(26, uiCount);
btnTest.BtnAdd(18, uiCount);
btnTest.BtnAdd(22, uiCount); //
btnTest.BtnAdd(5, uiCount); //
btnTest.BtnAdd(42, uiCount);
btnTest.BtnAdd(13, uiCount);
btnTest.BtnAdd(46, uiCount);
btnTest.BtnAdd(27, uiCount);
btnTest.BtnAdd(27, uiCount); // duplicity call BtnUpdates()
btnTest.BtnAdd(8, uiCount);
btnTest.BtnAdd(32, uiCount); //
btnTest.BtnAdd(38, uiCount);
btnTest.BtnAdd(24, uiCount);
btnTest.BtnAdd(27, uiCount); // duplicity call BtnUpdates()
btnTest.BtnAdd(45, uiCount);
btnTest.BtnAdd(25, uiCount); //
// output: 5,7,8,10,13,15,18,20,22,24,25,26,27,30,32,35,38,40,42,45,46,
foreach(KeyValuePair<int, uint>? keyValue in btnTest)
Console.Write(keyValue.GetValueOrDefault().Key + ",");
Console.WriteLine();
// output: 5,7,8,10,13,15,18,20,22,24,25,26,
FcsBTreeN<int, uint>.BtnEnumerator btnEn = btnTest.GetEnumeratorEx(false, 12);
while (btnEn.MoveNext())
Console.Write(btnEn.Current.Key + ",");
btnEn.Dispose();
Console.WriteLine();
int keyLo = 22;
int keyHi = 38;
// output: 5,7,8,10,13,15,18,20,22,24,25,26,27,30,32,35,38,
btnEn = btnTest.GetEnumeratorEx(default(int), keyHi, false);
while (btnEn.MoveNext())
Console.Write(btnEn.Current.Key + ",");
Console.WriteLine();
btnEn.Dispose();
// output: 22,24,25,26,27,30,32,35,38,40,42,45,46,
btnEn = btnTest.GetEnumeratorEx(keyLo, default(int), false);
while (btnEn.MoveNext())
Console.Write(btnEn.Current.Key + ",");
Console.WriteLine();
btnEn.Dispose();
// output: 22,24,25,26,27,30,32,35,38,
btnEn = btnTest.GetEnumeratorEx(keyLo, keyHi, false);
while (btnEn.MoveNext())
Console.Write(btnEn.Current.Key + ",");
Console.WriteLine();
// output: 22,24,25,26,27,30,32,35,38,
btnEn.Reset();
while (btnEn.MoveNext())
Console.Write(btnEn.Current.Key + ",");
Console.WriteLine();
btnEn.Dispose();
// output: 22,24,25,26,27,
btnEn = btnTest.GetEnumeratorEx(keyLo, keyHi, false, 5);
while (btnEn.MoveNext())
Console.Write(btnEn.Current.Key + ",");
Console.WriteLine();
btnEn.Dispose();
// ---------- REVERSE ----------
Console.WriteLine("-----------------------------------");
// output: 46,45,42,40,38,35,32,30,27,26,25,24,22,20,18,15,13,10,8,7,5,
btnEn = btnTest.GetEnumeratorEx(true);
while (btnEn.MoveNext())
Console.Write(btnEn.Current.Key + ",");
Console.WriteLine();
btnEn.Dispose();
// output: 46,45,42,40,38,35,32,30,27,26,25,24,
btnEn = btnTest.GetEnumeratorEx(true, 12);
while (btnEn.MoveNext())
Console.Write(btnEn.Current.Key + ",");
Console.WriteLine();
btnEn.Dispose();
// output: 38,35,32,30,27,26,25,24,22,20,18,15,13,10,8,7,5,
btnEn = btnTest.GetEnumeratorEx(default(int), keyHi, true);
while (btnEn.MoveNext())
Console.Write(btnEn.Current.Key + ",");
Console.WriteLine();
btnEn.Dispose();
// output: 46,45,42,40,38,35,32,30,27,26,25,24,22,
btnEn = btnTest.GetEnumeratorEx(keyLo, default(int), true);
while (btnEn.MoveNext())
Console.Write(btnEn.Current.Key + ",");
Console.WriteLine();
btnEn.Dispose();
// output: 38,35,32,30,27,26,25,24,22,
btnEn = btnTest.GetEnumeratorEx(keyLo, keyHi, true);
while (btnEn.MoveNext())
Console.Write(btnEn.Current.Key + ",");
Console.WriteLine();
btnEn.Dispose();
// output: 38,35,32,30,27,
btnEn = btnTest.GetEnumeratorEx(keyLo, keyHi, true, 5);
while (btnEn.MoveNext())
Console.Write(btnEn.Current.Key + ",");
Console.WriteLine();
btnEn.Dispose();
Console.WriteLine("-----------------------------------");
Console.WriteLine("Key ENTER press.");
Console.ReadLine();
}
}
}