Commit 9c336ba0 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Get rid of mdict (into .junk). Fixes #10.

git-svn-id: file:///svn/tokudb@849 c7de825b-a66e-492c-adef-691d508d4ae1
parent 9a8fd72c
...@@ -69,7 +69,6 @@ check: bins ...@@ -69,7 +69,6 @@ check: bins
$(DTOOL) ./brt-test $(DTOOL) ./brt-test
$(DTOOL) ./hashtest $(DTOOL) ./hashtest
./benchmark-test --valsize 256 --verify 1 ./benchmark-test --valsize 256 --verify 1
# ./mdict-test
check-fanout: check-fanout:
let BRT_FANOUT=4; \ let BRT_FANOUT=4; \
...@@ -95,13 +94,11 @@ log.o: log_header.h log-internal.h log.h wbuf.h crc.h brttypes.h $(BRT_INTERNAL_ ...@@ -95,13 +94,11 @@ log.o: log_header.h log-internal.h log.h wbuf.h crc.h brttypes.h $(BRT_INTERNAL_
brt-test.o brt.o: brt.h ../include/db.h hashtable.h pma.h brttypes.h cachetable.h memory.h brt-test.o brt.o: brt.h ../include/db.h hashtable.h pma.h brttypes.h cachetable.h memory.h
brt-serialize-test.o: $(BRT_INTERNAL_H_INCLUDES) brt-serialize-test.o: $(BRT_INTERNAL_H_INCLUDES)
brt.o: $(BRT_INTERNAL_H_INCLUDES) key.h log_header.h brt.o: $(BRT_INTERNAL_H_INCLUDES) key.h log_header.h
mdict.o: pma.h
hashtable.o: hashtable.h brttypes.h memory.h key.h yerror.h ../include/db.h hashfun.h hashtable.o: hashtable.h brttypes.h memory.h key.h yerror.h ../include/db.h hashfun.h
memory.o: memory.h memory.o: memory.h
primes.o: primes.h primes.o: primes.h
hashtest: hashtable.o memory.o primes.o hashtest: hashtable.o memory.o primes.o
brt-serialize.o: $(BRT_INTERNAL_H_INCLUDES) key.h wbuf.h rbuf.h brt-serialize.o: $(BRT_INTERNAL_H_INCLUDES) key.h wbuf.h rbuf.h
mdict-test: hashtable.o pma.o memory.o
brt-bigtest: memory.o ybt.o brt.o pma.o cachetable.o key.o hashtable.o brt-serialize.o brt-bigtest: memory.o ybt.o brt.o pma.o cachetable.o key.o hashtable.o brt-serialize.o
brt-bigtest.o: brt.h ../include/db.h brt-bigtest.o: brt.h ../include/db.h
log-test: log.o memory.o log-test: log.o memory.o
......
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007 Tokutek Inc. All rights reserved."
#include "mdict.h"
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
void verify_mdict_instance (bytevec kv_v, ITEMLEN kl, bytevec dv_v, ITEMLEN dl,
int N, int *data, char *saw) {
char *kv = (char*)kv_v;
char *dv = (char*)dv_v;
int num, k;
assert(kv[0]=='k');
assert(dv[0]=='d');
assert(strcmp(kv+1, dv+1)==0);
assert(strlen(kv)+1==kl);
assert(strlen(dv)+1==dl);
num = atoi(kv+1);
for (k=0; k<N; k++) {
if (data[k]==num) {
assert(!saw[k]);
saw[k]=1;
return;
}
}
fprintf(stderr, "%s isn't there\n", kv); abort();
}
void verify_mdict (MDICT mdict, int N, int *data, char *saw) {
int j;
for (j=0; j<N; j++) {
saw[j]=0;
}
MDICT_ITERATE(mdict, kv, kl, dv, dl,
verify_mdict_instance (kv, kl, dv, dl,
N, data, saw));
for (j=0; j<N; j++) {
assert(saw[j]);
}
}
void test0 (void) {
int r, i, j;
MDICT mdict;
int n_ops=1000;
int *data=malloc(sizeof(*data)*n_ops);
char*saw =malloc(sizeof(*saw)*n_ops);
int data_n = 0;
assert(data!=0);
r = mdict_create(&mdict); assert(r==0);
assert(mdict_n_entries(mdict)==0);
{
bytevec kv=(void*)0xdeadbeef;
bytevec dv=(void*)0xbeefdead;
ITEMLEN kl=42, dl=43;
r = mdict_find_last(mdict,&kv,&kl,&dv,&dl);
assert(r!=0);
assert((unsigned long)kv==0xdeadbeef);
assert((unsigned long)dv==0xbeefdead);
assert(kl==42);
assert(dl==43);
}
for (i=0; i<n_ops; i++) {
if (random()%4==1) {
// Delete something random
} else if (random()%2 == 0) {
// Insert something
try_another_random:
{
int ra = random()%(1<<30);
char kv[100], dv[100];
for (j=0; j<data_n; j++) {
if (ra==data[j]) goto try_another_random;
}
snprintf(kv, 99, "k%d", ra);
snprintf(dv, 99, "d%d", ra);
mdict_insert(mdict, kv, strlen(kv)+1, dv, strlen(dv)+1);
data[data_n++]=ra;
}
} else {
// Look up something
}
verify_mdict(mdict, data_n, data, saw);
}
}
int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__))) {
test0();
return 0;
}
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007 Tokutek Inc. All rights reserved."
#include "mdict.h"
#include "memory.h"
#define USEPMA
#ifdef USEPMA
#include "pma.h"
struct mdict {
PMA pma;
};
int mdict_create (MDICT* mdict) {
MDICT result;
int r;
MALLOC(result);
if (result==0) return -1;
r = toku_pma_create(&result->pma);
if (r==0) {
*mdict = result;
}
return r;
}
void mdict_free (MDICT m) {
toku_pma_free(m->pma);
my_free(m);
}
int mdict_n_entries (MDICT m) {
return toku_pma_n_entries(m->pma);
}
/* Returns an error if the key is already present. */
/* The values returned should not be modified. */
/* May damage the cursor. */
int mdict_insert (MDICT m, bytevec key, ITEMLEN keylen, bytevec data, ITEMLEN datalen) {
return toku_pma_insert(m->pma, key, keylen, data, datalen);
}
/* This returns an error if the key is NOT present. */
int mdict_replace (MDICT, bytevec key, ITEMLEN keylen, bytevec data, ITEMLEN datalen);
/* This returns an error if the key is NOT present. */
int mdict_delete (MDICT m, bytevec key, ITEMLEN keylen) {
return toku_pma_delete(m->pma, key, keylen);
}
/* Exposes internals of the MDICT by returning a pointer to the guts.
* Don't modify the returned data. Don't free it. */
int mdict_lookup (MDICT m, bytevec key, ITEMLEN keylen, bytevec*data, ITEMLEN *datalen) {
return toku_pma_lookup(m->pma, key, keylen, data, datalen);
}
int mdict_random_pick(MDICT m, bytevec *key, ITEMLEN *keylen, bytevec *data, ITEMLEN *datalen) {
return toku_pma_random_pick(m->pma, key, keylen, data, datalen);
}
void mdict_iterate (MDICT m, void(*f)(bytevec,ITEMLEN,bytevec,ITEMLEN, void*), void*v) {
toku_pma_iterate(m->pma, f, v);
}
#else
foo
#endif
#ifndef MDICT_H
#define MDICT_H
#ident "Copyright (c) 2007 Tokutek Inc. All rights reserved."
#include "brttypes.h"
//#define USEPMA
#define USEHASH
int toku_keycompare (bytevec key1, ITEMLEN key1len, bytevec key2, ITEMLEN key2len);
#ifdef USEPMA
#include "pma.h"
#define MDICT PMA
#define MDICT_OK PMA_OK
#define MDICT_NOTFOUND PMA_NOTFOUND
#define mdict_free toku_pma_free
#define mdict_n_entries toku_pma_n_entries
#define MDICT_ITERATE PMA_ITERATE
#define mdict_insert toku_pma_insert
#define mdict_create pma_create
#define mdict_delete pma_delete
#define mdict_lookup toku_pma_lookup
#define mdict_random_pick toku_pma_random_pick
#define mdict_iterate pma_iterate
#elif defined(USEHASH)
#include "hashtable.h"
#define MDICT HASHTABLE
#define MDICT_OK 0
#define MDICT_NOTFOUND -1
#define MDICT_ALREADY_THERE -2
#define mdict_free hashtable_free
#define mdict_n_entries hashtable_n_entries
#define MDICT_ITERATE HASHTABLE_ITERATE
#define mdict_insert hash_insert
#define mdict_create hashtable_create
#define mdict_delete hash_delete
#define mdict_lookup hash_find
#define mdict_random_pick hashtable_random_pick
#define mdict_iterate hashtable_iterate
#define mdict_find_last hashtable_find_last
#else
/* In-memory dictionary. */
enum mdict_errors { MDICT_OK=0, MDICT_NOTFOUND = -1, MDICT_ALREADY_THERE = -2 };
typedef struct mdict *MDICT;
int mdict_create (MDICT*);
void mdict_free (MDICT);
int mdict_n_entries (MDICT);
/* Returns an error if the key is already present. */
/* The values returned should not be modified. */
/* May damage the cursor. */
int mdict_insert (MDICT, bytevec key, ITEMLEN keylen, bytevec data, ITEMLEN datalen);
/* This returns an error if the key is NOT present. */
int mdict_replace (MDICT, bytevec key, ITEMLEN keylen, bytevec data, ITEMLEN datalen);
/* This returns an error if the key is NOT present. */
int mdict_delete (MDICT, bytevec key, ITEMLEN keylen);
/* Exposes internals of the MDICT by returning a pointer to the guts.
* Don't modify the returned data. Don't free it. */
int mdict_lookup (MDICT, bytevec key, ITEMLEN keylen, bytevec*data, ITEMLEN *datalen);
int mdict_random_pick(MDICT, bytevec *key, ITEMLEN *keylen, bytevec *data, ITEMLEN *datalen);
void mdict_iterate (MDICT, void(*)(bytevec,ITEMLEN,bytevec,ITEMLEN, void*), void*);
#define MDICT_ITERATE(table,keyvar,keylenvar,datavar,datalenvar,body) ({ \
void __do_iterate(bytevec keyvar, ITEMLEN keylenvar, bytevec datavar, ITEMLEN datalenvar, void *__ignore __attribute__((__unused__))) { \
body; \
} \
mdict_iterate(table,__do_iterate, 0); \
})
#endif
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment