mariadb/newbrt/mdict.c
Bradley C. Kuszmaul 2f8ec84fb8 Rename
git-svn-id: file:///svn/tokudb@4 c7de825b-a66e-492c-adef-691d508d4ae1
2007-07-13 19:37:47 +00:00

64 lines
1.6 KiB
C

#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 = pma_create(&result->pma);
if (r==0) {
*mdict = result;
}
return r;
}
void mdict_free (MDICT m) {
pma_free(m->pma);
my_free(m);
}
int mdict_n_entries (MDICT m) {
return 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 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 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 pma_lookup(m->pma, key, keylen, data, datalen);
}
int mdict_random_pick(MDICT m, bytevec *key, ITEMLEN *keylen, bytevec *data, ITEMLEN *datalen) {
return pma_random_pick(m->pma, key, keylen, data, datalen);
}
void mdict_iterate (MDICT m, void(*f)(bytevec,ITEMLEN,bytevec,ITEMLEN, void*), void*v) {
pma_iterate(m->pma, f, v);
}
#else
foo
#endif