/* Return the next symbol in the iteration through the block's dictionary. */ static PyObject * blpy_block_syms_iternext (PyObject *self) { block_syms_iterator_object *iter_obj = (block_syms_iterator_object *) self; struct symbol *sym; BLPY_ITER_REQUIRE_VALID (iter_obj->source); if (!iter_obj->initialized_p) { sym = dict_iterator_first (iter_obj->dict, &(iter_obj->iter)); iter_obj->initialized_p = 1; } else sym = dict_iterator_next (&(iter_obj->iter)); if (sym == NULL) { PyErr_SetString (PyExc_StopIteration, _("Symbol is null.")); return NULL; } return symbol_to_symbol_object (sym); }
int main() { size_t i = 0, m, max=100000; char buf[128]; struct timeval beg, end; long sec ; dict *d = dict_create(&opts); for(m = 0; m < 3; m++) { for(i = 0; i < max; i++) { memset(buf, 0, sizeof(buf)); snprintf(buf, sizeof(buf), ";;%lu;;", i); dict_add(d, buf, buf); } printf("add %d, %d %llu\n", DICT_USED(d), DICT_CAP(d),used_mem()); for(i = 0; i < max; i++) { dict_entry *entry; memset(buf, 0, sizeof(buf)); snprintf(buf, sizeof(buf), ";;%lu;;", i); entry = dict_find(d, buf); if(strcmp((char*)entry->value, (char*)buf) != 0) abort(); } printf("find %d, %d %llu\n", DICT_USED(d), DICT_CAP(d),used_mem()); for(i = 0; i < max; i++) { memset(buf, 0, sizeof(buf)); snprintf(buf, sizeof(buf), ";;%lu;;", i); dict_replace(d, buf, buf); } printf("prelace %d, %d %llu\n", DICT_USED(d), DICT_CAP(d),used_mem()); for(i = 0; i < max; i++) { memset(buf, 0, sizeof(buf)); snprintf(buf, sizeof(buf), ";;%lu;;", i); dict_del(d, buf); } printf("delete %d, %d %llu\n", DICT_USED(d), DICT_CAP(d),used_mem()); } dict_expand(d, max*2); printf("%d, %d %llu\n", DICT_USED(d), DICT_CAP(d),used_mem()); printf("%d %llu\n", DICT_CAP(d),used_mem()); dict_destroy(d); printf("%llu\n", used_mem()); d = dict_create(&opts); gettimeofday(&beg, NULL); for(i = 0; i < 1000000; i++) { memset(buf, 0, sizeof(buf)); snprintf(buf, sizeof(buf), "%lu", i); dict_add(d, buf, buf); } gettimeofday(&end, NULL); sec = (end.tv_sec - beg.tv_sec)*1000; sec += (end.tv_usec - beg.tv_usec)/1000; printf("add msec %ld, mm: %llu\n", sec, used_mem()); gettimeofday(&beg, NULL); dict_iterator *iter = dict_get_iterator(d); dict_entry *entry = NULL; i = 0; while((entry = dict_iterator_next(iter)) != NULL){ i++; } dict_iterator_destroy(iter); gettimeofday(&end, NULL); sec = (end.tv_sec - beg.tv_sec)*1000; sec += (end.tv_usec - beg.tv_usec)/1000; printf("iterator msec %ld, times: %lu mm: %llu\n", sec, i, used_mem()); gettimeofday(&beg, NULL); for(i = 0; i < 1000000; i++) { memset(buf, 0, sizeof(buf)); snprintf(buf, sizeof(buf), "%lu", i); dict_del(d, buf); } gettimeofday(&end, NULL); sec = (end.tv_sec - beg.tv_sec)*1000; sec += (end.tv_usec - beg.tv_usec)/1000; printf("remove msec %ld, mm: %llu\n", sec, used_mem()); dict_destroy(d); printf("%llu\r\n", used_mem()); return 0; }