diff --git a/btree.h b/btree.h index 777ce56..40247ea 100644 --- a/btree.h +++ b/btree.h @@ -1,8 +1,9 @@ #ifndef BTREE_H #define BTREE_H -#include "btypes.h" // integer definitions -#include "btree_vfs.h" // bTreeVFS class +#include "btypes.h" // integer definitions +#include "btree_vfs.h" // bTreeVFS class +#include "btree_key.h" // bTree key functions enum treeTypes { BT_CUSTOM, BT_PCHAR, BT_STRING, BT_SINGLE, BT_DOUBLE, BT_INT32, BT_INT64 }; @@ -52,10 +53,6 @@ treeTypes treeType; } __attribute__((__packed__)); -typedef int (*compareKeyFunc)(void *, void *); -typedef void (*copyKeyProc)(void *, void *); -typedef int (*keySizeFunc)(void *); - class bTree { protected: compareKeyFunc compareKey; diff --git a/btree_key.cpp b/btree_key.cpp new file mode 100644 index 0000000..04d45b8 --- /dev/null +++ b/btree_key.cpp @@ -0,0 +1,125 @@ +#include "btree_key.h" +#include "btypes.h" +#include + +int +compareKeyNull(void *, void *) { + return 0; +} // compareKeyNull + +int +compareKeyString(void * , void * ) { + return 0; +} // compareKeyString + +int +compareKeyPChar(void * key1, void * key2) { + return strcmp((char *)key1, (char *)key2); +} // compareKeyPChar + +int +compareKeySingle(void * , void * ) { + return 0; +} // compareKeySingle + +int +compareKeyDouble(void * , void * ) { + return 0; +} // compareKeyDouble + +int +compareKeyInt32(void * , void * ) { + return 0; +} // compareKeyInt32 + +int +compareKeyInt64(void * , void * ) { + return 0; +} // compareKeyInt64 + +/* + * CopyKey functions + */ + +void +copyKeyNull(void *, void *) { + return; +} // copyKeyNull + +void +copyKeyString(void *, void *) { + +} // copyKeyString + +void +copyKeyPChar(void *, void *) { + +} // copyKeyPChar + +void +copyKeySingle(void * srcKey, void * destKey) { + if ((srcKey == NULL) || (destKey == NULL)) return; + *(float *)destKey = *(float *)srcKey; +} // copyKeySingle + +void +copyKeyDouble(void * srcKey, void * destKey) { + if ((srcKey == NULL) || (destKey == NULL)) return; + *(double *)destKey = *(double *)srcKey; +} // copyKeyDouble + +void +copyKeyInt32(void * srcKey, void * destKey) { + if ((srcKey == NULL) || (destKey == NULL)) return; + *(int32 *)destKey = *(int32 *)srcKey; +} // copyKeyInt32 + +void +copyKeyInt64(void * srcKey, void * destKey) { + if ((srcKey == NULL) || (destKey == NULL)) return; + *(int64 *)destKey = *(int64 *)srcKey; +} // copyKeyInt64 + +/* + * KeySize functions + */ + +int +keySizeNull(void *) { + return 0; +} // keySizeNull + +int +keySizeString(void * key) { + const char * charKey = static_cast(key); + if (charKey == NULL) return 0; + return ((int)charKey[0]+1); +} // keySizeString + +int +keySizePChar(void * key) { + const char * charKey = static_cast(key); + if (charKey == NULL) return 0; + return (strlen(charKey)+1); +} // keySizePChar + +int +keySizeSingle(void *) { + return sizeof(float); +} // keySizeSingle + +int +keySizeDouble(void *) { + return sizeof(double); +} + +int +keySizeInt32(void *) { + return sizeof(int32); +} + +int +keySizeInt64(void *) { + return sizeof(int64); +} + diff --git a/btree_key.h b/btree_key.h new file mode 100644 index 0000000..b7f4101 --- /dev/null +++ b/btree_key.h @@ -0,0 +1,32 @@ +#ifndef BTREE_KEY_H +#define BTREE_KEY_H + +typedef int (*compareKeyFunc)(void *, void *); +typedef void (*copyKeyProc)(void *, void *); +typedef int (*keySizeFunc)(void *); + +int compareKeyNull(void *, void *); +int compareKeyString(void *, void *); +int compareKeyPChar(void *, void *); +int compareKeySingle(void *, void *); +int compareKeyDouble(void *, void *); +int compareKeyInt32(void *, void *); +int compareKeyInt64(void *, void *); + +void copyKeyNull(void *, void *); +void copyKeyString(void *, void *); +void copyKeyPChar(void *, void *); +void copyKeySingle(void *, void *); +void copyKeyDouble(void *, void *); +void copyKeyInt32(void *, void *); +void copyKeyInt64(void *, void *); + +int keySizeNull(void *); +int keySizeString(void *); +int keySizePChar(void *); +int keySizeSingle(void *); +int keySizeDouble(void *); +int keySizeInt32(void *); +int keySizeInt64(void *); + +#endif