您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ DArray_create函数代码示例

51自学网 2021-06-01 20:17:36
  C++
这篇教程C++ DArray_create函数代码示例写得很实用,希望能帮到您。

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

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

示例1: 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,


示例2: 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,


示例3: _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,


示例4: expose_VM

static inline voidexpose_VM(STATE, VALUE lobby){  VALUE vm = Value_new(state, ObjectType);  Value_set(state, lobby, "VM", vm);  // VM.primitives map  DArray *prims    = DArray_create(sizeof(VALUE), 10);  VALUE primitives = Map_new(state, prims);  Value_set(state, vm, "primitives", primitives);  // Object  DEFPRIM("to_s", Primitive_to_s);  DEFPRIM("prototype", Primitive_prototype);  DEFPRIM("or", Primitive_or);  DEFPRIM("equals", Primitive_equals);  DEFPRIM("is", Primitive_is);  DEFPRIM("print", Primitive_print);  DEFPRIM("puts", Primitive_puts);  DEFPRIM("require", Primitive_require);  DEFPRIM("clone", Primitive_clone);  // Vector  DEFPRIM("vector_[]", Primitive_Vector_at);  DEFPRIM("vector_push", Primitive_Vector_push);  DEFPRIM("vector_to_map", Primitive_Vector_to_map);  DEFPRIM("vector_each", Primitive_Vector_each);  DEFPRIM("vector_each_with_index", Primitive_Vector_each_with_index);  // Number  DEFPRIM("number_+", Primitive_Number_add);  DEFPRIM("number_-", Primitive_Number_sub);  DEFPRIM("number_*", Primitive_Number_mul);  DEFPRIM("number_/", Primitive_Number_div);  DEFPRIM("number_<", Primitive_Number_lt);  DEFPRIM("number_>", Primitive_Number_gt);  // String  DEFPRIM("string_+", Primitive_String_concat);  // Map  DEFPRIM("map_each", Primitive_Map_each);  // VM.types map  DArray *ts = DArray_create(sizeof(VALUE), 10);  VALUE types = Map_new(state, ts);  Value_set(state, vm, "types", types);  DEFVALUE("object", Object_bp);  DEFVALUE("number", Number_bp);  DEFVALUE("string", String_bp);  DEFVALUE("vector", Vector_bp);  DEFVALUE("map", Map_bp);  DEFVALUE("closure", Closure_bp);}
开发者ID:txus,项目名称:terrorvm,代码行数:56,


示例5: kernel_files

static inline DArray*kernel_files(STATE){  DArray *entries = DArray_create(sizeof(bstring), 10);  bstring kernel_relative_path = bfromcstr("../kernel");  bstring absolute_path = resolve_path(state, kernel_relative_path);  struct dirent **namelist;  int n = scandir(bdata(absolute_path), &namelist, 0, alphasort);  if (n < 0) {    perror("scandir");  } else {    for(int i = 0; i < n; i++) {      if(strcmp(namelist[i]->d_name, ".") != 0 && strcmp(namelist[i]->d_name, "..") != 0) {        DArray_push(entries, bfromcstr(namelist[i]->d_name));      }      free(namelist[i]);    }    free(namelist);  }  bdestroy(absolute_path);  bdestroy(kernel_relative_path);  return entries;}
开发者ID:txus,项目名称:terrorvm,代码行数:27,


示例6: malloc

Parallax *Parallax_create() {    Parallax *parallax = malloc(sizeof(Parallax));    check(parallax != NULL, "Could not create parallax");    parallax->layers = DArray_create(sizeof(ParallaxLayer), 8);    parallax->camera = NULL;    GfxSize level = {1, 1};    parallax->level_size = level;    parallax->sky_color.rgba.r = 0.5;    parallax->sky_color.rgba.g = 0.5;    parallax->sky_color.rgba.b = 1.0;    parallax->sky_color.rgba.a = 1.0;    parallax->sea_color.rgba.r = 0.0;    parallax->sea_color.rgba.g = 0.5;    parallax->sea_color.rgba.b = 0.0;    parallax->sea_color.rgba.a = 1.0;    parallax->y_wiggle = 0.0;    parallax->sea_level = 1.0;    return parallax;error:    if (parallax) free(parallax);    return NULL;}
开发者ID:broccolini,项目名称:dabes_engine,代码行数:27,


示例7: calloc

static inline TSTree *TSTree_insert_base(TSTree *root, TSTree *node,          const char *key, size_t len, void *value){  if(node == NULL) {    node = (TSTree *) calloc(1, sizeof(TSTree));    check(node != NULL, "Failed creating node");    node->values = DArray_create(DEFAULT_DARRAY_SIZE, DEFAULT_DARRAY_SIZE);    if(root == NULL) root = node;    node->splitchar = *key;  }  if(*key < node->splitchar) {    node->low = TSTree_insert_base(root, node->low, key, len, value);  } else if(*key == node->splitchar) {    if(len > 1) {      node->equal = TSTree_insert_base(root, node->equal, key + 1, len - 1, value);    } else {        DArray_push(node->values, value);        return node;        // assert(node->value == NULL && "Duplicate insert into tst.");    }  } else {      node->high = TSTree_insert_base(root, node->high, key, len, value);  }  return node;error:  return NULL;}
开发者ID:Azdaroth,项目名称:liblcthw,代码行数:34,


示例8: DArray_create

char *test_iterationBackward_arrayContainingContinousElements(){    DArray *array = DArray_create(sizeof(intptr_t), 3);    DArray_push(array, (void *) (intptr_t) 60);    DArray_push(array, (void *) (intptr_t) 670);    DArray_push(array, (void *) (intptr_t) 90);    int index = -1;    assert(DArray_iterator_prev(array, &index) == 1 && "Expected to continue to prev element.");    assert(index == 2 && "Expected index was not set by iteration.");    assert(DArray_iterator_prev(array, &index) == 1 && "Expected to continue to prev element.");    assert(index == 1 && "Expected index was not set by iteration.");    assert(DArray_iterator_prev(array, &index) == 1 && "Expected to continue to prev element.");    assert(index == 0 && "Expected index was not set by iteration.");    assert(DArray_iterator_prev(array, &index) == 0 && "Expected to end interation.");    DArray_destroy(array);    return NULL;}
开发者ID:maxbeutel,项目名称:learn-c-the-hard-way,代码行数:25,


示例9: DArray_create

char *test_distribution(){    int i = 0;    int stats[3][BUCKETS] = { {0} };    DArray *keys = DArray_create(0, NUM_KEYS);    mu_assert(gen_keys(keys, NUM_KEYS) == 0,            "Failed to generate random keys.");    fill_distribution(stats[ALGO_FNV1A], keys, Hashmap_fnv1a_hash);    fill_distribution(stats[ALGO_ADLER32], keys, Hashmap_adler32_hash);    fill_distribution(stats[ALGO_DJB], keys, Hashmap_djb_hash);    fprintf(stderr, "FNV/tA32/tDJB/n");    for (i = 0; i < BUCKETS; i++) {        fprintf(stderr, "%d/t%d/t%d/n",                stats[ALGO_FNV1A][i],                stats[ALGO_ADLER32][i], stats[ALGO_DJB][i]);    }    destroy_keys(keys);    return NULL;}
开发者ID:ifzz,项目名称:liblcthw,代码行数:25,


示例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,


示例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,


示例12: DArray_create

DArray *TSTree_collect(TSTree *root, const char *prefix, size_t len){  DArray *matches = DArray_create(sizeof(char *), 100);  TSTree *node = root;  size_t i = 0;  while (i < len && node) {    if (prefix[i] < node->splitchar) {      node = node->low;    } else if (prefix[i] > node->splitchar) {      node = node->high;    } else {      assert(prefix[i] == node->splitchar && "Prefix should == splitchar");      i++;      if (i < len) {        node = node->equal;      }    }  }  // node is the node that matches the prefix; all nodes in the tree will match  char *partial_match = malloc(sizeof(char) * (len - 1));  memcpy(partial_match, prefix, (len - 1));  _TSTree_collect_sub_nodes(node, matches, partial_match, len);  return matches;}
开发者ID:shterrett,项目名称:learn-c-the-hard-way,代码行数:25,


示例13: String_to_object

Object*String_to_object(bstring string){  Object *obj = NULL;  if (bchar(string, 0) == '"') {    int len = blength(string) - 2;    obj = Object_create_string(bmidstr(string, 1, len));  } else if (bchar(string, 0) == '[') {    int strlen = blength(string) - 2;    bstring inner_str = bmidstr(string, 1, strlen);    struct bstrList *elements = bsplit(inner_str, ',');    int len = elements->qty;    int i = 0;    DArray *array = DArray_create(sizeof(Object*), len);    bstring *ptr = elements->entry;    for(i = 0; i < len; i++) {      btrimws(*ptr);      DArray_push(array, String_to_object(*ptr));      ptr++;    }    obj = Object_create_array(array);  } else {    int value = atoi(bdata(string));    if (value != 0) {      obj = Object_create_integer(atoi(bdata(string)));    } else {      return NULL;    }  }  return obj;}
开发者ID:txus,项目名称:shitdb,代码行数:34,


示例14: DArray_mergesort

int DArray_mergesort(DArray *array, DArray_compare cmp){  int count = array->end;  if (count > 1) {    int pivot = count / 2;    int after_pivot = count - pivot;    DArray *left = DArray_create(array->element_size, pivot);    DArray *right = DArray_create(array->element_size, after_pivot);    for (int i = 0; i < pivot; i++) {      DArray_push(left, DArray_get(array, i));    }    for (int i = pivot; i < count; i++) {      DArray_push(right, DArray_get(array, i));    }    DArray_mergesort(left, cmp);    DArray_mergesort(left, cmp);    int i = 0;    int l_ptr = 0;    int r_ptr = 0;    for (i = 0; i < count; i++) {      if (l_ptr >= pivot) {        DArray_set(array, i, DArray_get(right, r_ptr));        r_ptr++;      } else if (r_ptr >= after_pivot) {        DArray_set(array, i, DArray_get(left, l_ptr));        l_ptr++;      } else if (cmp(DArray_get(left, l_ptr), DArray_get(right, r_ptr)) < 0) {        DArray_set(array, i, DArray_get(left, l_ptr));        l_ptr++;      } else {        DArray_set(array, i, DArray_get(right, r_ptr));        r_ptr++;      }    }    DArray_destroy(left);    DArray_destroy(right);  }  return 0;}
开发者ID:shterrett,项目名称:learn-c-the-hard-way,代码行数:46,


示例15: DArray_create

char *test_create() {    array = DArray_create(sizeof(int), 100);    mu_assert(array != NULL, "DArray_create failed");    mu_assert(array->contents != NULL, "contents wrong in darray");    mu_assert(array->end == 0, "end isn't at the right spot");    mu_assert(array->element_size == sizeof(int), "element size is wrong");    mu_assert(array->max == 100, "wrong max length on initial size");    return NULL;}
开发者ID:ajdecon,项目名称:play,代码行数:10,


示例16: DArray_create

DArray *create_words(){    DArray *result = DArray_create(0, 5);    char *words[] = {"asdfasfd", "werwar", "13234", "asdfasfd", "oioj"};    for(int i = 0; i < 5; i++) {        DArray_push(result, words[i]);    }    return result;}
开发者ID:wenzong,项目名称:lab,代码行数:11,


示例17: DArray_create

DArray *create_words(){	DArray *result = DArray_create(0, 7);	char *words[] = { "werwar", "asdasd", "13234", "oioj", "gthht", "lkluil", "xswcde" };	int i = 0;	for (i = 0; i < 7; i++) {		DArray_push(result, words[i]);	}	return result;}
开发者ID:jachness,项目名称:learnc,代码行数:12,


示例18: Hashmap_create

Hashmap *Hashmap_create(Hashmap_compare compare, Hashmap_hash hash){	Hashmap *map = calloc(1, sizeof(Hashmap));		map->compare = comare==NULL?default_compare:compare;	map->hash = hash==NULL?default_hash:hash;	map->buckets = DArray_create(sizeof(DArray *),DEFAULT_NUMBER_OF_BUCKETS);	map->buckets->end = map->buckets->max;		return map;}
开发者ID:deyimsf,项目名称:journal,代码行数:12,


示例19: CloseNodes_Create

CloseNodes *CloseNodes_Create(Hash *id){    CloseNodes *nodes = malloc(sizeof(CloseNodes));    check_mem(nodes);    nodes->id = *id;    nodes->close_nodes = DArray_create(sizeof(struct CloseNode *), BUCKET_K + 1);    check_mem(nodes->close_nodes);    return nodes;error:    free(nodes);    return NULL;}
开发者ID:polysome,项目名称:amok,代码行数:15,


示例20: DArray_find

DArray DArray_find(DArray array, DArray_find_fn *filter_fn, void* args){  if (DArray_is_empty(array)) return NULL;  DArray filtered = DArray_create(array->element_size, array->size);  for (int i = 0; i < DArray_count(array); i++) {    void *item = DArray_get(array, i);    if (filter_fn(item, args))      DArray_push(filtered, item);  }  return filtered;}
开发者ID:dash-project,项目名称:nasty-MPI,代码行数:15,


示例21: ChipmunkRecorder_clear_frames

void ChipmunkRecorder_clear_frames(Recorder *recorder) {    check(recorder != NULL, "No recorder to clear");    // Destroy frames    DArray_clear_destroy(recorder->frames);    recorder->frames = DArray_create(sizeof(ChipmunkRecorderFrame), 60 * 5);    recorder->num_frames = 0;    recorder->avg_frame_size = 0;    recorder->total_frame_size = 0;    return;error:    return;}
开发者ID:levicole,项目名称:dabes_engine,代码行数:15,


示例22: DArray_create

DArray *darray_init(int *array, size_t count){  DArray *darray = DArray_create(sizeof(int*), count);  INV_DARRAY(darray);    for (size_t i = 0; i < count; i++)    darray->contents[i] = &array[i];  darray->count = count;  INV_DARRAY(darray);  return darray; error:  return NULL;}
开发者ID:fbmnds,项目名称:lcthw,代码行数:16,


示例23: Hashmap_create

Hashmap* Hashmap_create(Hashmap_compare compare, Hashmap_hash hash) {    Hashmap* map = calloc(1, sizeof(Hashmap));    check_mem(map);    map->compare = compare == NULL ? default_compare : compare;    map->hash = hash == NULL ? default_hash : hash;    map->buckets = DArray_create(sizeof(DArray*), DEFAULT_NUMBER_OF_BUCKETS);    map->buckets->end = map->buckets->max; // fake out expanding it    check_mem(map->buckets);    return map;error:    if(map) Hashmap_destroy(map);    return NULL;}
开发者ID:fill1890,项目名称:lcthwlib,代码行数:16,



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


C++ DArray_get函数代码示例
C++ DArray_count函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。