本文整理汇总了C++中DArray_count函数的典型用法代码示例。如果您正苦于以下问题:C++ DArray_count函数的具体用法?C++ DArray_count怎么用?C++ DArray_count使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DArray_count函数的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);
}
}
示例2: 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;
}
示例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);
}
}
示例4: 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);
}
}
示例5: 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);
}
}
示例6: DArray_get
NodeAddress *getFSFromServicePool() {
NodeAddress *fsAddress = NULL;
if (DArray_count(fsList) > 0) {
fsAddress = DArray_get(fsList, fsPosition++);
if (fsPosition == DArray_count(fsList))
fsPosition = 0;
}
return fsAddress;
}
示例7: bfromcstr
char *test_getlines()
{
bstring str = bfromcstr("one\ntwo\nthree\nfour\nfive\n");
struct bstrList *file = bsplit(str, '\n');
DArray *lines = getlines(file, 2, 4);
bstring two = bfromcstr("two");
bstring three = bfromcstr("three");
bstring four = bfromcstr("four");
mu_assert(DArray_count(lines) == 3, "Wrong number of lines.");
mu_assert(bstrcmp((bstring)DArray_at(lines, 0), two) == 0, "First line is wrong.");
mu_assert(bstrcmp((bstring)DArray_at(lines, 1), three) == 0, "Second line is wrong.");
mu_assert(bstrcmp((bstring)DArray_at(lines, 2), four) == 0, "Third line is wrong.");
bstrListDestroy(file);
bdestroy(str);
bdestroy(two);
bdestroy(three);
bdestroy(four);
DArray_destroy(lines);
return NULL;
}
示例8: VM_start
void VM_start(bstring binary, bstring filename)
{
STATE = State_new();
Runtime_init(state);
VALUE lobby = Lobby_new(state); // toplevel object
state->lobby = lobby;
state->binary = binary;
BytecodeFile *file = BytecodeFile_new(state, filename);
int fn_count = DArray_count(file->function_names);
for(int j=0; j < fn_count; j++) {
bstring fn_name = (bstring)DArray_at(file->function_names, j);
Function *fn = (Function*)Hashmap_get(file->functions, fn_name);
Hashmap_set(state->functions, fn_name, fn);
}
bstring main_fn = bfromcstr("0_main");
CallFrame *top_frame = CallFrame_new(lobby, STATE_FN(main_fn), NULL);
bdestroy(main_fn);
top_frame->name = "main";
Stack_push(FRAMES, top_frame);
// now we're ready to bootstrap
State_bootstrap(state);
// and run the codes!
VM_run(state);
State_destroy(state);
}
示例9: State_bootstrap
void
State_bootstrap(STATE)
{
DArray *filenames = kernel_files(state);
int count = DArray_count(filenames);
// Expose toplevel constants
expose_VM(state, state->lobby);
int reenable_debugger = 0;
// Disable debugger while loading kernel files
if(Debug) {
reenable_debugger = 1;
Debug = 0;
}
// Load all files.
for(int i=0; i < count; i++) {
bstring filename = (bstring)DArray_at(filenames, i);
bstring path = bfromcstr("kernel/");
bconcat(path, filename);
Primitive_require(state, String_new(state, bdata(path)), NULL, NULL);
bdestroy(path);
bdestroy(filename);
}
DArray_destroy(filenames);
// Reenable debugger if needed
if(reenable_debugger) Debug = 1;
}
示例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;
}
示例11: Value_print_all
void Value_print_all(STATE, DArray* objs)
{
for(int i=0; i < DArray_count(objs); i++) {
Value_print(state, (VALUE)DArray_at(objs, i));
printf("\n");
}
}
示例12: CloseNodes_Add
int
CloseNodes_Add(CloseNodes *close, Node *node)
{
assert(close != NULL && "NULL CloseNodes pointer");
assert(node != NULL && "NULL Node pointer");
Distance distance = Hash_Distance(&close->id, &node->id);
int i = FindIndex(close->close_nodes, &distance);
if (i < 0)
return 0;
struct CloseNode *close_node = malloc(sizeof(struct CloseNode));
check_mem(close_node);
close_node->node = node;
close_node->distance = distance;
if (DArray_count(close->close_nodes) < BUCKET_K)
DArray_push(close->close_nodes, NULL);
ShiftFrom(close->close_nodes, i);
DArray_set(close->close_nodes, i, close_node);
return 0;
error:
return -1;
}
示例13: DArray_qsort
int DArray_qsort(DArray* array, DArray_compare cmp)
{
DArray_check(array);
qsort(array->contents, DArray_count(array), sizeof(void*), cmp);
return 0;
error:
return 1;
}
示例14: get_parents
int* get_parents(const FeaturedSentence sent) {
int *parents = (int*) malloc(sizeof (int) * (DArray_count(sent->words) + 1));
check_mem(parents);
parents[0] = -1;
for (int i = 0; i < DArray_count(sent->words); i++) {
Word w = (Word) DArray_get(sent->words, i);
parents[i + 1] = w->parent;
}
return parents;
error:
log_err("Error in allocating parents");
exit(1);
}
示例15: Vector_each_with_index
void Vector_each_with_index(VALUE vector, Vector_iter_idx iter)
{
DArray *array = VAL2ARY(vector);
int count = DArray_count(array);
for(int i=0; i<count; i++) {
iter((VALUE)DArray_at(array, i), i);
}
}