diff options
author | George Hazan <george.hazan@gmail.com> | 2015-03-21 19:15:39 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-03-21 19:15:39 +0000 |
commit | aebb257da0067c98c292bc62ad73200cc3a9dba7 (patch) | |
tree | bf3d47189a35bfc6c78ac4e6b7baf48a455650b8 /tools/MakeDef/tnsrtcol.cpp | |
parent | 2e286299cea4063e71845616138e92299af42744 (diff) |
DEF-file automatic creator
git-svn-id: http://svn.miranda-ng.org/main/trunk@12473 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'tools/MakeDef/tnsrtcol.cpp')
-rw-r--r-- | tools/MakeDef/tnsrtcol.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tools/MakeDef/tnsrtcol.cpp b/tools/MakeDef/tnsrtcol.cpp new file mode 100644 index 0000000000..b614f8388b --- /dev/null +++ b/tools/MakeDef/tnsrtcol.cpp @@ -0,0 +1,78 @@ +#include <stdio.h>
+#include <string.h>
+
+#include "h_collection.h"
+
+HSortedCollection::HSortedCollection( ccIndex aLimit, ccIndex aDelta ) :
+ HCollection( aLimit, aDelta ),
+ duplicates( false )
+{
+}
+
+int HSortedCollection::compare( const void *key1, const void *key2 ) const
+{
+ return strcmp(( const char* )key1, ( const char* )key2 );
+}
+
+ccIndex HSortedCollection::indexOf( const void *item )
+{
+ ccIndex i;
+
+ if ( search( keyOf( item ), i ) == false )
+ return ccNotFound;
+
+ if ( duplicates )
+ while( i < count && item != items[i] )
+ i++;
+
+ return ( i < count ) ? i : ccNotFound;
+}
+
+bool HSortedCollection::insert( void* item )
+{
+ ccIndex i;
+ if ( search( keyOf( item ), i ) == 0 || duplicates )
+ return atInsert( i, item );
+
+ return false;
+}
+
+const void* HSortedCollection::keyOf( const void* item ) const
+{
+ return item;
+}
+
+void* HSortedCollection::search( const void* key )
+{
+ ccIndex temp;
+
+ if ( search( key, temp ) == false )
+ return 0;
+
+ return items[ temp ];
+}
+
+bool HSortedCollection::search( const void* key, ccIndex& index )
+{
+ ccIndex l = 0;
+ ccIndex h = count - 1;
+ bool res = false;
+
+ while( l <= h )
+ { ccIndex i = ( l+h )/2;
+
+ int c = compare( keyOf( items[ i ] ), key );
+ if ( c < 0 )
+ l = i + 1;
+ else
+ { h = i - 1;
+ if ( c == 0 )
+ { res = true;
+ lastItem = i;
+ if ( !duplicates )
+ l = i;
+ } } }
+
+ index = l;
+ return res;
+}
|