コード例 #1
0
ファイル: wi-data.c プロジェクト: ProfDrLuigi/zanka
wi_data_t * wi_data_init_with_capacity(wi_data_t *data, wi_uinteger_t capacity) {
	data->capacity	= WI_MAX(wi_exp2m1(wi_log2(capacity) + 1), _WI_DATA_MIN_SIZE);
	data->bytes		= wi_malloc(data->capacity);
	data->free		= true;
	
	return data;
}
コード例 #2
0
ファイル: wi-string.c プロジェクト: ProfDrLuigi/zanka
wi_string_t * wi_string_init_with_capacity(wi_string_t *string, wi_uinteger_t capacity) {
	string->capacity	= WI_MAX(wi_exp2m1(wi_log2(capacity) + 1), _WI_STRING_MIN_SIZE);
	string->string		= wi_malloc(string->capacity);
	string->length		= 0;
	string->free		= true;
	
	return string;
}
コード例 #3
0
ファイル: wi-dictionary.c プロジェクト: haifenghuang/libwired
wi_dictionary_t * wi_dictionary_init_with_capacity_and_callbacks(wi_dictionary_t *dictionary, wi_uinteger_t capacity, wi_dictionary_key_callbacks_t key_callbacks, wi_dictionary_value_callbacks_t value_callbacks) {
    dictionary->key_callbacks           = key_callbacks;
    dictionary->value_callbacks         = value_callbacks;
    dictionary->bucket_chunks_offset    = _wi_dictionary_buckets_per_page;
    dictionary->min_count               = WI_MAX(wi_exp2m1(wi_log2(capacity) + 1), _WI_DICTIONARY_MIN_COUNT);
    dictionary->buckets_count           = dictionary->min_count;
    dictionary->buckets                 = wi_malloc(dictionary->buckets_count * sizeof(_wi_dictionary_bucket_t *));

    return dictionary;
}
コード例 #4
0
ファイル: wi-set.c プロジェクト: ProfDrLuigi/zanka
wi_set_t * wi_set_init_with_capacity_and_callbacks(wi_set_t *set, wi_uinteger_t capacity, wi_set_callbacks_t callbacks) {
	set->callbacks				= callbacks;
	set->bucket_chunks_offset	= _wi_set_buckets_per_page;
	set->min_count				= WI_MAX(wi_exp2m1(wi_log2(capacity) + 1), _WI_SET_MIN_COUNT);
	set->buckets_count			= set->min_count;
	set->buckets				= wi_malloc(set->buckets_count * sizeof(_wi_set_bucket_t *));
	set->lock					= wi_rwlock_init(wi_rwlock_alloc());
	
	return set;
}
コード例 #5
0
ファイル: wi-array.c プロジェクト: ProfDrLuigi/zanka
wi_array_t * wi_array_init_with_capacity_and_callbacks(wi_array_t *array, wi_uinteger_t capacity, wi_array_callbacks_t callbacks) {
	array->callbacks			= callbacks;
	array->item_chunks_offset	= _wi_array_items_per_page;
	array->items_count			= WI_MAX(wi_exp2m1(wi_log2(capacity) + 1), _WI_ARRAY_MIN_COUNT);
	array->min_count			= array->items_count;
	array->items				= wi_malloc(array->items_count * sizeof(_wi_array_item_t *));
	array->lock					= wi_rwlock_init(wi_rwlock_alloc());
	
	return array;
}
コード例 #6
0
ファイル: wi-string.c プロジェクト: ProfDrLuigi/zanka
static void _wi_string_grow(wi_string_t *string, wi_uinteger_t capacity) {
	capacity = WI_MAX(wi_exp2m1(wi_log2(capacity) + 1), _WI_STRING_MIN_SIZE);

	if(string->free) {
		string->string = wi_realloc(string->string, capacity);
	} else {
		string->string = wi_malloc(capacity);
		string->free = true;
	}

	string->capacity = capacity;
}
コード例 #7
0
ファイル: wi-set.c プロジェクト: ProfDrLuigi/zanka
static void _wi_set_resize(wi_set_t *set) {
	_wi_set_bucket_t	**buckets, *bucket, *next_bucket;
	wi_uinteger_t		i, index, capacity, buckets_count;

	capacity		= wi_exp2m1(wi_log2(set->data_count) + 1);
	buckets_count	= WI_CLAMP(capacity, set->min_count, _WI_SET_MAX_COUNT);
	buckets			= wi_malloc(buckets_count * sizeof(_wi_set_bucket_t *));

	for(i = 0; i < set->buckets_count; i++) {
		for(bucket = set->buckets[i]; bucket; bucket = next_bucket) {
			next_bucket		= bucket->next;
			index			= _WI_SET_HASH(set, bucket->data) % buckets_count;
			bucket->next	= buckets[index];
			buckets[index]	= bucket;
		}
	}

	wi_free(set->buckets);

	set->buckets		= buckets;
	set->buckets_count	= buckets_count;
}
コード例 #8
0
ファイル: wi-dictionary.c プロジェクト: haifenghuang/libwired
static void _wi_dictionary_optimize(wi_dictionary_t *dictionary) {
    _wi_dictionary_bucket_t     **buckets, *bucket, *next_bucket;
    wi_uinteger_t               i, index, capacity, buckets_count;

    capacity        = wi_exp2m1(wi_log2(dictionary->key_count) + 1);
    buckets_count   = WI_CLAMP(capacity, dictionary->min_count, _WI_DICTIONARY_MAX_COUNT);
    buckets         = wi_malloc(buckets_count * sizeof(_wi_dictionary_bucket_t *));

    for(i = 0; i < dictionary->buckets_count; i++) {
        for(bucket = dictionary->buckets[i]; bucket; bucket = next_bucket) {
            next_bucket     = bucket->next;
            index           = _WI_DICTIONARY_KEY_HASH(dictionary, bucket->key) % buckets_count;
            bucket->next    = buckets[index];
            buckets[index]  = bucket;
        }
    }

    wi_free(dictionary->buckets);

    dictionary->buckets         = buckets;
    dictionary->buckets_count   = buckets_count;
}