diff --git a/btree_key.cpp b/btree_key.cpp index 8b16fce..996ea48 100644 --- a/btree_key.cpp +++ b/btree_key.cpp @@ -14,26 +14,60 @@ int compareKeyPChar(void * key1, void * key2) { - return strcmp((char *)key1, (char *)key2); + const char * charKey1 = static_cast(key1); + const char * charKey2 = static_cast(key2); + return strcmp(charKey1, charKey2); } // compareKeyPChar int -compareKeySingle(void * , void * ) { +compareKeySingle(void * key1, void * key2) { + if ((key1 == NULL) || (key2 == NULL)) return 0; + + const float * floatKey1 = static_cast(key1); + const float * floatKey2 = static_cast(key2); + + if (*floatKey1 < *floatKey2) return -1; + else if (*floatKey1 > *floatKey2) return 1; + return 0; } // compareKeySingle int -compareKeyDouble(void * , void * ) { +compareKeyDouble(void * key1, void * key2) { + if ((key1 == NULL) || (key2 == NULL)) return 0; + + const double * doubleKey1 = static_cast(key1); + const double * doubleKey2 = static_cast(key2); + + if (*doubleKey1 < *doubleKey2) return -1; + else if (*doubleKey1 > *doubleKey2) return 1; + return 0; } // compareKeyDouble int compareKeyInt32(void * , void * ) { + if ((key1 == NULL) || (key2 == NULL)) return 0; + + const int32 * int32Key1 = static_cast(key1); + const int32 * int32Key2 = static_cast(key2); + + if (*int32Key1 < *int32Key2) return -1; + else if (*int32Key1 > *int32Key2) return 1; + return 0; } // compareKeyInt32 int -compareKeyInt64(void * , void * ) { +compareKeyInt64(void * key1, void * key2) { + if ((key1 == NULL) || (key2 == NULL)) return 0; + + const int64 * int64Key1 = static_cast(key1); + const int64 * int64Key2 = static_cast(key2); + + if (*int64Key1 < *int64Key2) return -1; + else if (*int64Key1 > *int64Key2) return 1; + return 0; } // compareKeyInt64