Beispiel #1
0
static ht_entry
hash_current_node_value(const struct node *node)
{
	ht_entry entry;

	entry = ht_set_depth(HT_NULL, node->depth);

	if (node->best_move == 0) {
		if (node->alpha < 0 || node->repetition_affected_any == 0)
			entry = ht_set_value(entry,
			    vt_upper_bound, node->alpha);
	}
	else if (node->value >= node->beta) {
		if (node->beta > 0 || node->repetition_affected_best == 0)
			entry = ht_set_value(entry, vt_lower_bound, node->beta);
	}
	else {
		int type = 0;
		if (node->value < 0 || node->repetition_affected_any == 0)
			type |= vt_upper_bound;
		if (node->value > 0 || node->repetition_affected_best == 0)
			type |= vt_lower_bound;

		if (type != 0)
			entry = ht_set_value(entry, type, node->value);
	}

	return entry;
}
static void test_hashitem_set_and_get() {

    hash_table table = ht_new();

    char* key = "hello";
    int value = 100;
    ht_set_value(&table, key, (void *) &value);

    int* value_get = (int *)ht_get_value(&table, key);
    assert(value == *value_get
           && "The value set is not the same as the get");
}
static void test_hashitem_collisions() {

    hash_table table = ht_new();

    /*The keys k1 and k2 create the same index.*/
    char *k1 = "2WwtnwoDx";
    int v1 = 10;
    ht_set_value(&table, k1, &v1);

    char *k2 = "2Uiihmi2/";
    int v2 = 20;
    ht_set_value(&table, k2, &v2);

    int* v1_get = (int *)ht_get_value(&table, k1);
    assert(v1 == *v1_get
           && "The value set is not the same as get");

    int* v2_get = (int *)ht_get_value(&table, k2);
    assert(v2 == *v2_get
           && "The value set is not the same as get");
}
static void test_hashitem_delete() {

    hash_table table = ht_new();

    char* key = "hello";
    int value = 100;
    ht_set_value(&table, key, (void *) &value);

    int* value_get = (int *)ht_get_value(&table, key);
    assert(value == *value_get
           && "The value set is not the same as the get");

    ht_delete_value(&table, key);

    value_get = (int *)ht_get_value(&table, key);
    if (value_get != NULL) {
        assert(0 && "The value is not deleted.");
    }
}