Closed Bazist closed 7 years ago
Удаляем ключ 2.
Сюрприз 1: Удалился также и ключ 3!
Сюрприз 2: При попытке вставить ключ 2 обратно получаем SIGSEGV.
using namespace std;
uint32 totalHArrayTime = 0; uint32 totalDenseTime = 0; uint32 totalMapTime = 0; uint32 totalUnorderedMapTime = 0;
HArrayVarRAM ha;
ulong64 msclock() { return (ulong64)clock() * 1000 / CLOCKS_PER_SEC; //in ms }
uint32 key(const char c) { char key1 = new char[sizeof(uint32)]; memset(key1,0,sizeof(uint32)); strcpy(key1,c); return (uint32)(*key1); }
void search(const char msg, uint32 key1,uint32* key2) { HArrayFixPair pairs[32]; uint32 val = ha.getKeysAndValuesByRange(pairs,sizeof(pairs)/sizeof(HArrayFixPair),key1,key2); printf("%s %d\n",msg,val); for( int i=0; i<val; i++ ) { HArrayFixPair p = pairs[i]; printf(" val %d = ",i); int n = p.KeyLen; for( int n=0; n<p.KeyLen; n++ ) printf(" %d",p.Key[n]); printf(" = %d\n",p.Value); } }
int main() { printf("Pointer size: %ld\n",sizeof(void*));
uint32 key1[] = { 100 }; uint32 key2[] = { 100, 200 }; uint32 key3[] = { 100, 200, 300 }; ha.init(26); ha.insert(key1,sizeof(key1),12345678); ha.insert(key2,sizeof(key2),22345678); ha.insert(key3,sizeof(key3),32345678); uint32 ret = ha.getValueByKey(key1, sizeof(key1)); printf("%d -> %d\n",key1,ret); ret = ha.getValueByKey(key2, sizeof(key2)); printf("%d -> %d\n",key2,ret); ret = ha.getValueByKey(key3, sizeof(key3)); printf("%d -> %d\n",key3,ret); search("search",key1,key3); // delete 2 printf("delete %d\n",key2); ha.delValueByKey(key2, sizeof(key2), 0); ret = ha.getValueByKey(key2, sizeof(key2)); printf("%d -> %d\n",key2,ret); // get 3 -> 3 has disappeared too! ret = ha.getValueByKey(key3, sizeof(key3)); printf("%d -> %d\n",key3,ret); // re-insert 2 ha.insert(key2,sizeof(key2),22345678); ret = ha.getValueByKey(key2, sizeof(key2)); printf("%d -> %d\n",key2,ret); // get 3 -> may be 3 has resurrected? ret = ha.getValueByKey(key3, sizeof(key3)); printf("%d -> %d\n",key3,ret); ha.printStat(); ha.destroy(); return 0;
};
Fixed.
Удаляем ключ 2.
Сюрприз 1: Удалился также и ключ 3!
Сюрприз 2: При попытке вставить ключ 2 обратно получаем SIGSEGV.
include "stdafx.h"
include
include
include
include
include "HArrayInt.h"
include "HArrayVarRAM.h"
using namespace std;
uint32 totalHArrayTime = 0; uint32 totalDenseTime = 0; uint32 totalMapTime = 0; uint32 totalUnorderedMapTime = 0;
HArrayVarRAM ha;
ulong64 msclock() { return (ulong64)clock() * 1000 / CLOCKS_PER_SEC; //in ms }
uint32 key(const char c) { char key1 = new char[sizeof(uint32)]; memset(key1,0,sizeof(uint32)); strcpy(key1,c); return (uint32)(*key1); }
void search(const char msg, uint32 key1,uint32* key2) { HArrayFixPair pairs[32]; uint32 val = ha.getKeysAndValuesByRange(pairs,sizeof(pairs)/sizeof(HArrayFixPair),key1,key2); printf("%s %d\n",msg,val); for( int i=0; i<val; i++ ) { HArrayFixPair p = pairs[i]; printf(" val %d = ",i);
int n = p.KeyLen; for( int n=0; n<p.KeyLen; n++ ) printf(" %d",p.Key[n]); printf(" = %d\n",p.Value);
} }
int main() { printf("Pointer size: %ld\n",sizeof(void*));
};