当前位置: 首页>>代码示例>>C++>>正文


C++ DArray_get函数代码示例

本文整理汇总了C++中DArray_get函数的典型用法代码示例。如果您正苦于以下问题:C++ DArray_get函数的具体用法?C++ DArray_get怎么用?C++ DArray_get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了DArray_get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Hashmap_destroy

void Hashmap_destroy(Hashmap *map)
{
	int i = 0;
	int j = 0;

	if(map) 
	{
		if(map->buckets) 
		{
			for(i = 0; i < DArray_count(map->buckets); i++) 
			{
				DArray *bucket = DArray_get(map->buckets, i);
				if(bucket) 
				{
					for(j = 0; j < DArray_count(bucket); j++) 
					{
						free(DArray_get(bucket,j));
					}
					DArray_destroy(bucket);
				}
			}
			DArray_destroy(map->buckets);
		}
		free(map);
	}
}
开发者ID:vajarkov,项目名称:C-TUTORIAL,代码行数:26,代码来源:hashmap.c

示例2: Hashmap_destroy

void Hashmap_destroy(Hashmap *map, Hashmap_destroy_func destroy_f)
{
    int i = 0;
    int j = 0;

    if (map) {
        if (map->buckets) {
            for (i = 0; i < DArray_count(map->buckets); i++) {
                DArray *bucket = DArray_get(map->buckets, i);
                if (!bucket) continue;
                for (j = 0; j < DArray_count(bucket); j++) {
                    void *val = DArray_get(bucket, j);
                    HashmapNode *node = val;
                    bdestroy(node->key);
                    if (destroy_f != NULL) {
                        destroy_f(node->data);
                    }
                    free(val);
                }
                DArray_destroy(bucket);
            }
            DArray_destroy(map->buckets);
        }

        free(map);
    }
}
开发者ID:hunterbridges,项目名称:liblcthw,代码行数:27,代码来源:hashmap.c

示例3: Hashmap_destroy

void Hashmap_destroy(Hashmap *map)
{
    int i = 0;
    int j = 0;

    if (map) {
        if (map->buckets) {
            for (i = 0; i < DArray_count(map->buckets); i++) {
                DArray *bucket = DArray_get(map->buckets, i);
                if (bucket) {
                    for (j = 0; j < DArray_count(bucket); j++) {
                        HashmapNode *node = DArray_get(bucket, j);
                        if (node != NULL) {
                            free(node->data);
                            map->free_key(node->key);
                        }
                    }

                    DArray_clear_destroy(bucket);

                    DArray_remove(map->buckets, i);
                }
            }
            DArray_clear_destroy(map->buckets);
        }

        free(map);
    }
}
开发者ID:imej,项目名称:c,代码行数:29,代码来源:hashmap.c

示例4: _merge_sort

DArray* _merge_sort(DArray* array, DArray_compare cmp)
{
    DArray_check(array);
    if(array->end <= 1)
        return array;
    DArray* left = DArray_create(array->element_size, array->max);
    check_mem(left);
    DArray* right = DArray_create(array->element_size, array->max);
    check_mem(right);
    int middle = array->end/2;
    int i = 0;
    for(i = 0; i < array->end; i++) {
        if(i < middle) {
            DArray_push(left, DArray_get(array, i));
        } else {
            DArray_push(right, DArray_get(array, i));
        }
    }
    DArray* sort_left = _merge_sort(left, cmp);
    check(left != NULL, "Error in left merge sort");
    DArray* sort_right = _merge_sort(right, cmp);
    check(right != NULL, "Error in right merge sort");

    if(sort_left != left) DArray_destroy(left);
    if(sort_right != right) DArray_destroy(right);

    return _merge_array(sort_left, sort_right, cmp);
error:
    return NULL;
}
开发者ID:PaulForey,项目名称:learn-c-the-hard-way,代码行数:30,代码来源:darray_algos.c

示例5: Hashmap_destroy

void 
Hashmap_destroy(Hashmap *map)
{
	int i = 0;
	int j = 0;

	if(!map){
		return;
	}

	if(!map->buckets){
		return;
	}

	for(i = 0; i < DArray_count(map->buckets); i++){
		//用DArray作桶,但桶里的每个元素也是DArray
		//用DArray代替链表避免hash碰撞
		//最后一层的DArray里放的才是HashmapNode
		DArray *bucket = DArray_get(map->buckets, i);
		if(!bucket){
			continue;	
		}

		for(j = 0; j < DArray_count(bucket); j++){
			free(DArray_get(bucket,j));
		}
		DArray_destroy(bucket);
	}
}
开发者ID:deyimsf,项目名称:journal,代码行数:29,代码来源:hashmap.c

示例6: mu_assert

char *test_get()
{
    mu_assert(DArray_get(array, 0) == val1, "Wrong first value.");
    mu_assert(DArray_get(array, 1) == val2, "Wrong second value.");

    return NULL;
}
开发者ID:Ingon,项目名称:lcthw,代码行数:7,代码来源:darray_tests.c

示例7: sift_down

void sift_down(DArray *array, int start, int end, DArray_compare cmp)
{
  int root = start;
  int child;
  int swp;

  while (root * 2 + 1 <= end) {
    child = root * 2 + 1;
    swp = root;

    if (cmp(DArray_get(array, swp), DArray_get(array, child)) < 0) {
      swp = child;
    }

    if (child + 1 <= end &&
         (cmp(DArray_get(array, swp), DArray_get(array, child + 1))) < 0) {
      swp = child + 1;
    }

    if (swp == root) {
      return;
    } else {
      swap(array, root, swp);
      root = swp;
    }
  }
}
开发者ID:shterrett,项目名称:learn-c-the-hard-way,代码行数:27,代码来源:darray_algos.c

示例8: is_sorted

int is_sorted(DArray *array)
{
    int i = 0;

    for (i = 0; i < DArray_count(array) - 1; i++) {
        if (strcmp(DArray_get(array, i), DArray_get(array, i+1)) > 0) {
            return 0;
        }
    }
    return 1;
}
开发者ID:walrus7521,项目名称:code,代码行数:11,代码来源:darray_algos_tests.c

示例9: DArray_remove

char *test_remove() {
    int *val_check = DArray_remove(array, 0);
    mu_assert(val_check != NULL, "Should not get NULL");
    mu_assert(*val_check == *val1, "Should get the first value");
    mu_assert(DArray_get(array,0) == NULL, "Should be gone.");
    DArray_free(val_check);

    val_check = DArray_remove(array, 1);
    mu_assert(val_check != NULL, "Should not get NULL");
    mu_assert(*val_check == *val2, "Should get the second value");
    mu_assert(DArray_get(array,1) == NULL, "Should be gone.");
    DArray_free(val_check);
    
    return NULL;
}
开发者ID:ajdecon,项目名称:play,代码行数:15,代码来源:darray_tests.c

示例10: CloseNodes_GetNodes

DArray *
CloseNodes_GetNodes(CloseNodes *close)
{
    assert(close != NULL && "NULL CloseNodes pointer");

    DArray *nodes = DArray_create(sizeof(Node *),
            DArray_max(close->close_nodes));
    check(nodes != NULL, "DArray_create failed");

    int i = 0;
    for (i = 0; i < DArray_count(close->close_nodes); i++)
    {
        struct CloseNode *close_node = DArray_get(close->close_nodes, i);
        check(close_node != NULL, "NULL CloseNodes entry");
        check(close_node->node != NULL, "NULL Node pointer in CloseNodes entry");

        int rc = DArray_push(nodes, close_node->node);
        check(rc == 0, "DArray_push failed");
    }

    return nodes;
error:
    DArray_destroy(nodes);
    return NULL;
}
开发者ID:polysome,项目名称:amok,代码行数:25,代码来源:close.c

示例11: check

static inline DArray *Hashmap_find_bucket(Hashmap * map, void *key,
        int create,
        uint32_t * hash_out)
{
    uint32_t hash = map->hash(key);
    int bucket_n = hash % DEFAULT_NUMBER_OF_BUCKETS;
    check(bucket_n >= 0, "Invalid bucket found: %d", bucket_n);
    // store it for the return so the caller can use it
    *hash_out = hash;

    DArray *bucket = DArray_get(map->buckets, bucket_n);

    if (!bucket && create) {
        // new bucket, set it up
        bucket = DArray_create(
                sizeof(void *), DEFAULT_NUMBER_OF_BUCKETS);
        check_mem(bucket);
        DArray_set(map->buckets, bucket_n, bucket);
    }

    return bucket;

error:
    return NULL;
}
开发者ID:Gabygaojia,项目名称:liblcthw,代码行数:25,代码来源:hashmap.c

示例12: DArray_group_by

DArray DArray_group_by(DArray array, DArray_group_by_fn *group_by_fn)
{
  if (DArray_is_empty(array) || !group_by_fn) return NULL;

  DArray groups = DArray_create(sizeof(DArray), 10);
  DArray group;
  int idx;
  void *el;

  size_t count = (size_t) DArray_count(array);
  for (size_t i = 0; i < count; i++) {
    el = DArray_remove(array, i);
    if (!el) continue;
    idx = group_by_fn(el);
    if (idx == -1) continue;

    group = DArray_get(groups, idx);

    if (!group) {
      group = DArray_create(array->element_size, DArray_count(array) + 1);
      DArray_ensure_capacity(groups, idx + 1);
      DArray_set(groups, idx, group);
    }

    DArray_push(group, el);
  }

  return groups;
}
开发者ID:dash-project,项目名称:nasty-MPI,代码行数:29,代码来源:darray_algos.c

示例13: Hashmap_find_bucket

void *Hashmap_delete(Hashmap *map, void *key)
{
    uint32_t hash = 0;
    DArray *bucket = Hashmap_find_bucket(map, key, 0, &hash);
    if(!bucket) {
        return NULL;
    }

    int i = Hashmap_get_node(map, hash, bucket, key);
    if(i == -1) {
        return NULL;
    }

    HashmapNode *node = DArray_get(bucket, i);
    void *data = node->data;
    free(node);

    HashmapNode *ending = DArray_pop(bucket);

    if(ending != node) {
        // alright looks like it's not the last one, swap it.
        DArray_set(bucket, i, ending);
    }

    return data;
}
开发者ID:bane138,项目名称:lcthw,代码行数:26,代码来源:hashmap.c

示例14: DArray_create

char *test_copy() {
    DArray *orig = DArray_create(sizeof(int), 11);
    DArray *dest = DArray_create(sizeof(int), 11);

    int i = 0;
    for(i = 0; i < 10; i++) {
        int *el_to_add = DArray_new(orig);
        *el_to_add = i;
        mu_assert(DArray_push(orig, el_to_add) == 0, "Pushing to DArray failed.");
    }

    int rc = DArray_copy(orig, dest);
    mu_assert(rc == 0, "Copy failed.")

    mu_assert(orig->max == dest->max, "max did not copy properly.");
    mu_assert(orig->end == dest->end, "end did not copy properly.");
    mu_assert(orig->element_size == dest->element_size,
            "element_size did not copy properly.");
    mu_assert(orig->expand_rate == dest->expand_rate,
            "expand_rate did not copy properly.");

    for(i = 0; i < 10; i++) {
        int *val = DArray_get(dest, i);
        mu_assert(val != NULL, "Got NULL from copy.");
        mu_assert(*val == i,
                "Failed to copy contents correctly.");
    }

    return NULL;
}
开发者ID:reem,项目名称:LCTHW-Lib,代码行数:30,代码来源:darray_tests.c

示例15: DArray_create

 char *test_push_pop()
 {
     DArray *array = DArray_create(sizeof(intptr_t), 5);

     DArray_push(array, (void *) (intptr_t) 30);
     DArray_push(array, (void *) (intptr_t) 20);
     DArray_push(array, (void *) (intptr_t) 10);

     intptr_t value = (intptr_t) DArray_pop(array);
     assert(value == 10 && "pop'ed wrong value from array.");

     value = (intptr_t) DArray_pop(array);
     assert(value == 20 && "pop'ed wrong value from array.");

     value = (intptr_t) DArray_pop(array);
     assert(value == 30 && "pop'ed wrong value from array.");

     DArray_push(array, (void *) (intptr_t) 60);
     value = (intptr_t) DArray_get(array, 0);
     assert(value == 60 && "Getting value by index after pop'ing all values from array failed.");

     DArray_destroy(array);

     return NULL;
}
开发者ID:maxbeutel,项目名称:learn-c-the-hard-way,代码行数:25,代码来源:dynamic_array_test.c


注:本文中的DArray_get函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。