Skip to content

Commit ffce697

Browse files
committed
add .NET examples
1 parent 75f214d commit ffce697

File tree

20 files changed

+863
-26
lines changed

20 files changed

+863
-26
lines changed

BtnEnumerator.examples/Program.cs renamed to BtnEnumerator.Core.examples/Program.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Collections.Generic;
33
using FriendlyCSharp.Databases;
44

5-
namespace BtnEnumerator.examples
5+
namespace BtnEnumerator.Core.examples
66
{
77
public class TestKV : FcsBTreeN<int, uint>
88
{
@@ -28,6 +28,8 @@ class Program
2828
static void Main(string[] args)
2929
{
3030
Console.OutputEncoding = System.Text.Encoding.Unicode;
31+
Console.WriteLine("BtnEnumerator.Core11.examples");
32+
Console.WriteLine("-----------------------------");
3133

3234
uint uiCount = 1;
3335
TestKV btnTest = new TestKV();
@@ -104,7 +106,7 @@ static void Main(string[] args)
104106
btnEn.Dispose();
105107

106108
// ---------- REVERSE ----------
107-
Console.WriteLine();
109+
Console.WriteLine("-----------------------------");
108110
// output: 46,45,42,40,38,35,32,30,27,26,25,24,22,20,18,15,13,10,8,7,5,
109111
btnEn = btnTest.GetEnumeratorEx(true);
110112
while (btnEn.MoveNext())
@@ -147,7 +149,7 @@ static void Main(string[] args)
147149
Console.WriteLine();
148150
btnEn.Dispose();
149151

150-
Console.WriteLine();
152+
Console.WriteLine("-----------------------------");
151153
Console.WriteLine("Key ENTER press.");
152154
Console.ReadLine();
153155
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
5+
</startup>
6+
</configuration>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{543751D8-0433-4634-A221-7FB49AFCF81B}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>BtnEnumerator.NET.examples</RootNamespace>
10+
<AssemblyName>BtnEnumerator.NET.examples</AssemblyName>
11+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="System" />
36+
<Reference Include="System.Core" />
37+
<Reference Include="Microsoft.CSharp" />
38+
</ItemGroup>
39+
<ItemGroup>
40+
<Compile Include="Program.cs" />
41+
<Compile Include="Properties\AssemblyInfo.cs" />
42+
</ItemGroup>
43+
<ItemGroup>
44+
<None Include="App.config" />
45+
</ItemGroup>
46+
<ItemGroup>
47+
<PackageReference Include="FriendlyCSharp.Databases">
48+
<Version>1.0.2</Version>
49+
</PackageReference>
50+
</ItemGroup>
51+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
52+
</Project>
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using FriendlyCSharp.Databases;
4+
5+
namespace BtnEnumerator.NET.examples
6+
{
7+
public class TestKV : FcsBTreeN<int, uint>
8+
{
9+
protected override bool BtnUpdates(int keyAdd, uint valueAdd, ref uint valueUpdates, object objUpdates)
10+
{
11+
valueUpdates++;
12+
return true;
13+
}
14+
//////////////////////////
15+
protected override int BtnCompares(int keyX, int keyY, object objCmp)
16+
{
17+
// return less < 0, equal = 0, greater > 0
18+
return keyX - keyY;
19+
}
20+
//////////////////////////
21+
public TestKV() : base(2)
22+
{
23+
}
24+
}
25+
26+
class Program
27+
{
28+
static void Main(string[] args)
29+
{
30+
Console.OutputEncoding = System.Text.Encoding.Unicode;
31+
Console.WriteLine("BtnEnumerator.NET452.examples");
32+
Console.WriteLine("-----------------------------");
33+
34+
uint uiCount = 1;
35+
TestKV btnTest = new TestKV();
36+
// Build the tree
37+
btnTest.BtnAdd(20, uiCount);
38+
btnTest.BtnAdd(40, uiCount);
39+
btnTest.BtnAdd(10, uiCount);
40+
btnTest.BtnAdd(30, uiCount);
41+
btnTest.BtnAdd(15, uiCount); //
42+
btnTest.BtnAdd(35, uiCount);
43+
btnTest.BtnAdd(7, uiCount);
44+
btnTest.BtnAdd(26, uiCount);
45+
btnTest.BtnAdd(18, uiCount);
46+
btnTest.BtnAdd(22, uiCount); //
47+
btnTest.BtnAdd(5, uiCount); //
48+
btnTest.BtnAdd(42, uiCount);
49+
btnTest.BtnAdd(13, uiCount);
50+
btnTest.BtnAdd(46, uiCount);
51+
btnTest.BtnAdd(27, uiCount);
52+
btnTest.BtnAdd(27, uiCount); // duplicity call BtnUpdates()
53+
btnTest.BtnAdd(8, uiCount);
54+
btnTest.BtnAdd(32, uiCount); //
55+
btnTest.BtnAdd(38, uiCount);
56+
btnTest.BtnAdd(24, uiCount);
57+
btnTest.BtnAdd(27, uiCount); // duplicity call BtnUpdates()
58+
btnTest.BtnAdd(45, uiCount);
59+
btnTest.BtnAdd(25, uiCount); //
60+
61+
// output: 5,7,8,10,13,15,18,20,22,24,25,26,27,30,32,35,38,40,42,45,46,
62+
foreach (KeyValuePair<int, uint>? keyValue in btnTest)
63+
Console.Write(keyValue.GetValueOrDefault().Key + ",");
64+
Console.WriteLine();
65+
66+
// output: 5,7,8,10,13,15,18,20,22,24,25,26,
67+
FcsBTreeN<int, uint>.BtnEnumerator btnEn = btnTest.GetEnumeratorEx(false, 12);
68+
while (btnEn.MoveNext())
69+
Console.Write(btnEn.Current.GetValueOrDefault().Key + ",");
70+
btnEn.Dispose();
71+
Console.WriteLine();
72+
73+
int? keyLo = 22;
74+
int? keyHi = 38;
75+
// output: 5,7,8,10,13,15,18,20,22,24,25,26,27,30,32,35,38,
76+
btnEn = btnTest.GetEnumeratorEx(null, keyHi, false);
77+
while (btnEn.MoveNext())
78+
Console.Write(btnEn.Current.GetValueOrDefault().Key + ",");
79+
Console.WriteLine();
80+
btnEn.Dispose();
81+
82+
// output: 22,24,25,26,27,30,32,35,38,40,42,45,46,
83+
btnEn = btnTest.GetEnumeratorEx(keyLo, null, false);
84+
while (btnEn.MoveNext())
85+
Console.Write(btnEn.Current.GetValueOrDefault().Key + ",");
86+
Console.WriteLine();
87+
btnEn.Dispose();
88+
89+
// output: 22,24,25,26,27,30,32,35,38,
90+
btnEn = btnTest.GetEnumeratorEx(keyLo, keyHi, false);
91+
while (btnEn.MoveNext())
92+
Console.Write(btnEn.Current.GetValueOrDefault().Key + ",");
93+
Console.WriteLine();
94+
// output: 22,24,25,26,27,30,32,35,38,
95+
btnEn.Reset();
96+
while (btnEn.MoveNext())
97+
Console.Write(btnEn.Current.GetValueOrDefault().Key + ",");
98+
Console.WriteLine();
99+
btnEn.Dispose();
100+
101+
// output: 22,24,25,26,27,
102+
btnEn = btnTest.GetEnumeratorEx(keyLo, keyHi, false, 5);
103+
while (btnEn.MoveNext())
104+
Console.Write(btnEn.Current.GetValueOrDefault().Key + ",");
105+
Console.WriteLine();
106+
btnEn.Dispose();
107+
108+
// ---------- REVERSE ----------
109+
Console.WriteLine("-----------------------------");
110+
// output: 46,45,42,40,38,35,32,30,27,26,25,24,22,20,18,15,13,10,8,7,5,
111+
btnEn = btnTest.GetEnumeratorEx(true);
112+
while (btnEn.MoveNext())
113+
Console.Write(btnEn.Current.GetValueOrDefault().Key + ",");
114+
Console.WriteLine();
115+
btnEn.Dispose();
116+
117+
// output: 46,45,42,40,38,35,32,30,27,26,25,24,
118+
btnEn = btnTest.GetEnumeratorEx(true, 12);
119+
while (btnEn.MoveNext())
120+
Console.Write(btnEn.Current.GetValueOrDefault().Key + ",");
121+
Console.WriteLine();
122+
btnEn.Dispose();
123+
124+
// output: 38,35,32,30,27,26,25,24,22,20,18,15,13,10,8,7,5,
125+
btnEn = btnTest.GetEnumeratorEx(null, keyHi, true);
126+
while (btnEn.MoveNext())
127+
Console.Write(btnEn.Current.GetValueOrDefault().Key + ",");
128+
Console.WriteLine();
129+
btnEn.Dispose();
130+
131+
// output: 46,45,42,40,38,35,32,30,27,26,25,24,22,
132+
btnEn = btnTest.GetEnumeratorEx(keyLo, null, true);
133+
while (btnEn.MoveNext())
134+
Console.Write(btnEn.Current.GetValueOrDefault().Key + ",");
135+
Console.WriteLine();
136+
btnEn.Dispose();
137+
138+
// output: 38,35,32,30,27,26,25,24,22,
139+
btnEn = btnTest.GetEnumeratorEx(keyLo, keyHi, true);
140+
while (btnEn.MoveNext())
141+
Console.Write(btnEn.Current.GetValueOrDefault().Key + ",");
142+
Console.WriteLine();
143+
btnEn.Dispose();
144+
145+
// output: 38,35,32,30,27,
146+
btnEn = btnTest.GetEnumeratorEx(keyLo, keyHi, true, 5);
147+
while (btnEn.MoveNext())
148+
Console.Write(btnEn.Current.GetValueOrDefault().Key + ",");
149+
Console.WriteLine();
150+
btnEn.Dispose();
151+
152+
Console.WriteLine("-----------------------------");
153+
Console.WriteLine("Key ENTER press.");
154+
Console.ReadLine();
155+
}
156+
}
157+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("BtnEnumerator.NET451.examples")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("BtnEnumerator.NET451.examples")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("543751d8-0433-4634-a221-7fb49afcf81b")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

FcsFastBTreeN.benchmark/Program.cs renamed to FcsFastBTreeN.Core.benchmark/Program.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using System;
2-
using FriendlyCSharp.Databases;
32
using System.Collections.Generic;
43
using System.Diagnostics;
4+
using FriendlyCSharp.Databases;
55

6-
namespace FcsFastBTreeN.benchmark
6+
namespace FcsFastBTreeN.Core.benchmark
77
{
88
class Program
99
{
@@ -54,6 +54,9 @@ public override int GetHashCode(StructBtn x)
5454
static void Main(string[] args)
5555
{
5656
Console.OutputEncoding = System.Text.Encoding.Unicode;
57+
Console.WriteLine("FcsFastBTreeN.Core11.benchmark");
58+
Console.WriteLine("------------------------------");
59+
5760
int iPocetAdd = 0;
5861
Random r = new Random((int)DateTime.Now.Ticks);
5962
int[] aRand = new int[10000000];
@@ -74,7 +77,8 @@ static void Main(string[] args)
7477
long iMemOld = iMem;
7578
//
7679
//
77-
Console.WriteLine("\nFcsFastBTreeN");
80+
Console.WriteLine("------------------------------");
81+
Console.WriteLine("FcsFastBTreeN");
7882
TestKV btnTest = new TestKV();
7983
var swFcsKV = Stopwatch.StartNew();
8084
for (int i = 0; i < _max; i++)
@@ -109,7 +113,8 @@ static void Main(string[] args)
109113
Console.WriteLine($"{((double)(swFcsKV.Elapsed.TotalMilliseconds * 1000000) / iCompareCount),7:N2} ns [{swFcsKV.Elapsed.TotalMilliseconds,11} ms | {iCompareCount} ]{iCompareCount / swFcsKV.Elapsed.TotalSeconds,20:N0} IOPS");
110114
//
111115
//
112-
Console.WriteLine("\nSortedSet");
116+
Console.WriteLine("------------------------------");
117+
Console.WriteLine("SortedSet");
113118
SortedSet<StructBtn> sorted = new SortedSet<StructBtn>(Comparer<StructBtn>.Create((a, b) => a.CompareTo(b)));
114119
var swSorted = Stopwatch.StartNew();
115120
for (int i = 0; i < _max; i++)
@@ -136,7 +141,8 @@ static void Main(string[] args)
136141
Console.WriteLine($"{((double)(swSorted.Elapsed.TotalMilliseconds * 1000000) / iCompareCount),7:N2} ns [{swSorted.Elapsed.TotalMilliseconds,11} ms | {iCompareCount} ]{iCompareCount / swSorted.Elapsed.TotalSeconds,20:N0} IOPS");
137142
//
138143
//
139-
Console.WriteLine("\nHashSet");
144+
Console.WriteLine("------------------------------");
145+
Console.WriteLine("HashSet");
140146
var hash = new HashSet<StructBtn>(new StructBtnComparer());
141147
var swHash = Stopwatch.StartNew();
142148
for (int i = 0; i < _max; i++)
@@ -163,7 +169,8 @@ static void Main(string[] args)
163169
Console.WriteLine($"{((double)(swHash.Elapsed.TotalMilliseconds * 1000000) / iCompareCount),7:N2} ns [{swSorted.Elapsed.TotalMilliseconds,11} ms | {iCompareCount} ]{iCompareCount / swHash.Elapsed.TotalSeconds,20:N0} IOPS");
164170
//
165171
//
166-
Console.WriteLine("\nDictionary");
172+
Console.WriteLine("------------------------------");
173+
Console.WriteLine("Dictionary");
167174
var dic = new Dictionary<int, uint>();
168175
var swDic = Stopwatch.StartNew();
169176
for (int i = 0; i < _max; i++)
@@ -187,7 +194,8 @@ static void Main(string[] args)
187194
//
188195
iCompareCount = 0;
189196
int iCompareEquals = 0;
190-
Console.WriteLine("\nChecking for sorting and matching");
197+
Console.WriteLine("------------------------------");
198+
Console.WriteLine("Checking for sorting and matching");
191199
btnTest.BtnFastFirst(out fcsKey2, out fcsValue2, 2);
192200
foreach (StructBtn sortedSet in sorted)
193201
{
@@ -203,7 +211,7 @@ static void Main(string[] args)
203211
Console.WriteLine($"count SortedSet: {iCompareCount}");
204212
Console.WriteLine($"checking: {iCompareEquals}");
205213

206-
Console.WriteLine();
214+
Console.WriteLine("------------------------------");
207215
Console.WriteLine("Key ENTER press.");
208216
Console.ReadLine();
209217
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
5+
</startup>
6+
</configuration>

0 commit comments

Comments
 (0)