@@ -7,53 +7,6 @@ namespace DuplicityKeys.Core.sample
77{
88 class Program
99 {
10- static int CmpBtnKey ( BtnKey keyX , BtnKey keyY , object objCmp )
11- {
12- // return < 0 (less), = 0 (equal), > 0 (greater)
13- int iResult = String . Compare ( keyX . keyCity , keyY . keyCity , StringComparison . Ordinal ) ;
14- if ( iResult == 0 )
15- {
16- iResult = keyX . keyId . CompareTo ( keyY . keyId ) ;
17- //if (iResult == 0)
18- //{
19- // iResult = DateTime.Compare(key0, keyY.key0);
20- // if (iResult == 0)
21- // {
22- // iResult = string.Compare(key1, keyY.key1, true);
23- // if (iResult == 0)
24- // {
25- // iResult = key2.CompareTo(keyY.key2);
26- // }
27- // }
28- //}
29- }
30- return iResult ;
31- }
32- //
33- static bool FuncUpdate ( BtnKey keyAdd , ref BtnKey keyUpdate , object objUpdate )
34- {
35- // Resize ?
36- if ( keyUpdate . aValueDateTime . Length <= keyUpdate . valueCount )
37- {
38- if ( keyUpdate . aValueDateTime . Length >= 1024 )
39- Array . Resize < DateTime > ( ref keyUpdate . aValueDateTime , keyUpdate . aValueDateTime . Length + 256 ) ;
40- else
41- Array . Resize < DateTime > ( ref keyUpdate . aValueDateTime , keyUpdate . aValueDateTime . Length * 2 ) ;
42- }
43- // Resize ?
44- if ( keyUpdate . aValueRand . Length <= keyUpdate . valueCount )
45- {
46- if ( keyUpdate . aValueRand . Length >= 1024 )
47- Array . Resize < uint > ( ref keyUpdate . aValueRand , keyUpdate . aValueRand . Length + 256 ) ;
48- else
49- Array . Resize < uint > ( ref keyUpdate . aValueRand , keyUpdate . aValueRand . Length * 2 ) ;
50- }
51- // Update
52- keyUpdate . aValueDateTime [ keyUpdate . valueCount ] = keyAdd . aValueDateTime [ 0 ] ;
53- keyUpdate . aValueRand [ keyUpdate . valueCount ] = keyAdd . aValueRand [ 0 ] ;
54- keyUpdate . valueCount ++ ;
55- return true ;
56- }
5710 //
5811 private struct BtnKey
5912 {
@@ -65,6 +18,59 @@ private struct BtnKey
6518 public int valueCount ;
6619 public DateTime [ ] aValueDateTime ;
6720 public uint [ ] aValueRand ;
21+ //
22+ static int CmpBtnKey ( BtnKey keyX , BtnKey keyY , object objCmp )
23+ {
24+ // return < 0 (less), = 0 (equal), > 0 (greater)
25+ int iResult = String . Compare ( keyX . keyCity , keyY . keyCity , StringComparison . Ordinal ) ;
26+ if ( iResult == 0 )
27+ {
28+ iResult = keyX . keyId . CompareTo ( keyY . keyId ) ;
29+ //if (iResult == 0)
30+ //{
31+ // iResult = DateTime.Compare(key0, keyY.key0);
32+ // if (iResult == 0)
33+ // {
34+ // iResult = string.Compare(key1, keyY.key1, true);
35+ // if (iResult == 0)
36+ // {
37+ // iResult = key2.CompareTo(keyY.key2);
38+ // }
39+ // }
40+ //}
41+ }
42+ return iResult ;
43+ }
44+ //
45+ static bool FuncUpdate ( BtnKey keyAdd , ref BtnKey keyUpdate , object objUpdate )
46+ {
47+ // Resize ?
48+ if ( keyUpdate . aValueDateTime . Length <= keyUpdate . valueCount )
49+ {
50+ if ( keyUpdate . aValueDateTime . Length >= 1024 )
51+ Array . Resize < DateTime > ( ref keyUpdate . aValueDateTime , keyUpdate . aValueDateTime . Length + 256 ) ;
52+ else
53+ Array . Resize < DateTime > ( ref keyUpdate . aValueDateTime , keyUpdate . aValueDateTime . Length * 2 ) ;
54+ }
55+ // Resize ?
56+ if ( keyUpdate . aValueRand . Length <= keyUpdate . valueCount )
57+ {
58+ if ( keyUpdate . aValueRand . Length >= 1024 )
59+ Array . Resize < uint > ( ref keyUpdate . aValueRand , keyUpdate . aValueRand . Length + 256 ) ;
60+ else
61+ Array . Resize < uint > ( ref keyUpdate . aValueRand , keyUpdate . aValueRand . Length * 2 ) ;
62+ }
63+ // Update
64+ keyUpdate . aValueDateTime [ keyUpdate . valueCount ] = keyAdd . aValueDateTime [ 0 ] ;
65+ keyUpdate . aValueRand [ keyUpdate . valueCount ] = keyAdd . aValueRand [ 0 ] ;
66+ keyUpdate . valueCount ++ ;
67+ return true ;
68+ }
69+ //
70+ public static FcsKeyFastBTreeN < BtnKey > CreateFcsKeyFastBTreeN ( )
71+ {
72+ return new FcsKeyFastBTreeN < BtnKey > ( BtnKey . CmpBtnKey , BtnKey . FuncUpdate , 32 ) ;
73+ }
6874 }
6975 //
7076 //
@@ -103,7 +109,7 @@ static void Main(string[] args)
103109 BtnKey key ;
104110 key . aValueRand = new uint [ 1 ] ;
105111 key . aValueDateTime = new DateTime [ 1 ] ;
106- FcsKeyFastBTreeN < BtnKey > btnTest = new FcsKeyFastBTreeN < BtnKey > ( CmpBtnKey , FuncUpdate , 32 ) ;
112+ FcsKeyFastBTreeN < BtnKey > btnTest = BtnKey . CreateFcsKeyFastBTreeN ( ) ;
107113 var swFcsKV = Stopwatch . StartNew ( ) ;
108114 for ( int iter = 0 ; iter < 100 ; iter ++ )
109115 {
0 commit comments