Beispiel #1
0
// Open a shared dictionary.
static Dt_t *opendictionary(Mydisc_t *dc) {
    // Discipline for objects identified by their decimal values.
    dc->disc.key = DTOFFSET(Obj_t, value);
    dc->disc.size = sizeof(int);
    dc->disc.link = -1;
    dc->disc.makef = NULL;
    dc->disc.freef = NULL;
    dc->disc.comparf = mycompare;
    dc->disc.hashf = myhash;
    dc->disc.memoryf = mymemory;
    dc->disc.eventf = NULL;

    Dt_t *dt = dtopen(&dc->disc, Dtrhset);  // open dictionary with hash-trie
    if (!dt) terror("Can't open dictionary");
    dtcustomize(dt, DT_SHARE, 1);  // turn on concurrent access mode
    return dt;
}
Beispiel #2
0
/* test the various insertion strategies */

typedef struct _obj_s
{	Dtlink_t	link;
	int		key;
} Obj_t;

static int intcompare(Dt_t* dt, Void_t* arg1, Void_t* arg2, Dtdisc_t* disc)
{
	int	*o1 = (int*)arg1;
	int	*o2 = (int*)arg2;
	return *o1 - *o2;
}

Dtdisc_t	Disc =
{	DTOFFSET(Obj_t, key), sizeof(int),  
	DTOFFSET(Obj_t, link),
	0, 0, intcompare, 0, 0, 0
};

tmain()
{
	Obj_t	obj, chk1, chk2, chk22;
	Dt_t	*dt;

	obj.key = 1;
	chk1.key = 1;
	chk2.key = 2;
	chk22.key = 2;

	if(!(dt = dtopen(&Disc, Dtoset)) )
Beispiel #3
0
typedef struct _obj_s {
    Dtlink_t link;
    int key;
} Obj_t;

static int intcompare(Dt_t *dt, void *arg1, void *arg2, Dtdisc_t *disc) {
    UNUSED(dt);
    UNUSED(disc);
    int *o1 = (int *)arg1;
    int *o2 = (int *)arg2;

    return *o1 - *o2;
}

Dtdisc_t Disc = {
    DTOFFSET(Obj_t, key), sizeof(int), DTOFFSET(Obj_t, link), 0, 0, intcompare, 0, 0, 0};

tmain() {
    UNUSED(argc);
    UNUSED(argv);
    Obj_t obj, chk1, chk2, chk22;
    Dt_t *dt;

    obj.key = 1;
    chk1.key = 1;
    chk2.key = 2;
    chk22.key = 2;

    if (!(dt = dtopen(&Disc, Dtoset))) terror("Can't open Dtoset dictionary");
    if (dtinsert(dt, &obj) != &obj) terror("dtinsert failed");
    if (dtinsert(dt, &chk1) != &obj) terror("dtinsert should have returned obj");