示例#1
0
int main() {
	struct bucket_array* b = ba_init();
	struct generic_data d;
	d.key = "music";
	d.key_l = 5;
	d.value = 2;
	printf("This new bucket has %d elements.\n", ba_size(b));

	ba_insert(b, d, 4);
	printf("Now, this bucket has %d elements.\n", ba_size(b));
	struct generic_data *p_d = ba_get(b, 4, "music", 5);
	printf("Let's see what's there: %s\n", p_d->key);
	printf("Let's remove this entry. ");
	ba_remove(b, 4, "music", 5);
	printf("The new size of the bucket array is %d.\n", ba_size(b));
	d.key = "hiking";
	d.key_l = 6;
	d.value = 5;
	ba_insert(b, d, 4);
	printf("Let's add a new element, and the new size is %d.\n", ba_size(b));
	p_d = ba_get(b, 4, "hiking", 5);
	printf("The new element is: %s, %d\n", p_d->key, p_d->value);
	d.value = 10;
	ba_set(b, 4, "hiking", 5, d.value);
	p_d = ba_get(b, 4, "hiking", 5);
	printf("Set %s to %d\n", p_d->key, p_d->value); 
	ba_insert(b, d, 20);
	ba_increase(b);
	
}
示例#2
0
int ht_remove(hash_tbl_t *h, key_t qKey) {
	uint32_t b_number = h->func->compress(h->func->hash(qKey));
	struct generic_data *result = ba_get(h->buckets, b_number, qKey);
	if(result==NULL)
		return NULL;
	else {
		ba_remove(h->buckets, b_number, qKey);
		return result->value;
	}
}
示例#3
0
void ht_put(hash_tbl_t *h, key_t nKey, int nValue) {
	uint32_t b_number = h->func->compress(h->func->hash(nkey));
	struct generic_data d;
	if(ba_get(h->buckets, b_number, nKey) == NULL) {
		d.key = key;
		d.value = value;
		ba_insert(h->buckets, d, b_number); 
	} else
		ba_set(h->buckets, b_number, key, value);
}
示例#4
0
/* Behaviour of BitArray.get(index) */
static PyObject *
BitArray_get(BitArray *self, PyObject *args) {
    const unsigned int index;
    if(!PyArg_ParseTuple(args, "I", &index))
        return NULL;

    if(index > self->num_elements) {
        PyErr_SetString(PyExc_IndexError, "Index out of bounds");
        return NULL;
    }
    int result = (int)ba_get(self->bitarray_pointer, index);
    return Py_BuildValue("i", result);
}
示例#5
0
int ht_get(hash_tbl_t *h, key_t qKey) {
	uint32_t b_number = h->func->compress(h->func->hash(qKey));
	struct generic_data *d = ba_get(h->buckets, b_number, qKey);
	return d->value;
}