Node *ListFind(List *a_list, int number) { if (a_list->size <= number || number < 0) { return NULL; } Iterator *iter; iter->node = a_list->head; for (int i = 0; i < number; ++i) { IteratorNext(iter); } return iter->node; }
uint64_t sum(SCtx& ctx) { uint64_t sum = 0; #if defined(IMPL_DM_HASHTABLE) ctx.ht.Iterate(sum_callback, &sum); #else auto it = IteratorBegin(ctx.ht); auto itend = IteratorEnd(ctx.ht); for( ; it != itend; IteratorNext(ctx.ht, it) ) sum += IteratorGetValue(ctx.ht, it); #endif return sum; }
void ListExchange(List *a_list) { if (a_list->size == 0 || a_list->size == 1) { return; } Iterator first; Iterator med; Iterator last; first.node = a_list->head; med.node = a_list->head; for (int i = 1; i < a_list->size / 2 ; ++i) { IteratorNext(&med); } last = med; IteratorNext(&last); med.node->next = NULL; a_list->head = last.node; while (IteratorNext(&last) != NULL) { } last.node->next = first.node; a_list->last = med.node; }
uint64_t iterator_prefix(SCtx& ctx) { ASSERT( Size(ctx.ht) == ctx.num_elements ); uint64_t sum = 0; #if defined(IMPL_DM_HASHTABLE) ctx.ht.Iterate(sum_callback, &sum); #else iterator_t it = IteratorBegin(ctx.ht); iterator_t itend = IteratorEnd(ctx.ht); for( ; it != itend; IteratorNext(ctx.ht, it) ) sum += IteratorGetValue(ctx.ht, it); #endif return sum; }
uint64_t create_insert_and_sum(SCtx& ctx) { hashtable_t ht; Init(ht, ctx.num_elements); for( size_t i = 0; i < ctx.num_elements; ++i ) Put(ht, keey_t( i ), value_t( i ) ); uint64_t sum = 0; #if defined(IMPL_DM_HASHTABLE) ht.Iterate(sum_callback, &sum); #else auto it = IteratorBegin(ht); auto itend = IteratorEnd(ht); for( ; it != itend; IteratorNext(ht, it) ) sum += IteratorGetValue(ht, it); #endif return sum; }