void howbigisyourp_dump(t_howbigisyourp *x) { t_an_item *item; t_atom a; t_linklist *list = linklist_new(); linklist_flags(list, OBJ_FLAG_MEMORY); // will use sysmem_freeptr on the objects // first item of list contains the totalnumberofobjects item = an_item_new(gensym("totalnumberofobjects"), 0); linklist_append(list, item); // copy the hash table to a linklist, and count the total number of object hashtab_funall(x->hash, (method)howbigisyourp_cp_to_linklist, list); // get the first item totalnumberofobjects which now contains the total number of objects item = linklist_getindex(list, 0); post("The total number of objects is %d", item->val); linklist_deleteindex(list, 0); // remove it so we can proceed // sorting is nicer linklist_sort(list, linklist_ascending); // iterate through the linklist and output {name, instances} out the outlet. item = linklist_getindex(list, 0); while (item) { atom_setlong(&a, item->val); outlet_anything(x->out, item->name, 1, &a); linklist_next(list, item, (void **)&item); } // free the linklist items, the hashtab items are not removed). if (list) object_free(list); }
void avl_bfs_dump(struct avl *avl, dump dmp) { struct avl_node *node = avl->root; struct linklist *list; int depth = 0, idx = 0, tmp = 0; int pre_depth = -1, pre_idx_line = -1; int height = avl_height(avl); if (!node) return; if ((list = linklist_new()) == NULL) return; if (linklist_insert(list, node, (void *) (long int) depth, NULL)) goto fail; while (linklist_size(list) > 0) { node = (struct avl_node *) linklist_remove_head(list, (void **) &depth, (void **) &tmp); if (node) _node_bfs_dump(node->value, depth, idx, height, dmp, &pre_depth, &pre_idx_line); if (linklist_insert(list, node ? node->left : NULL, (void *) (long int) (depth + 1), NULL)) goto fail; if (linklist_insert(list, node ? node->right : NULL, (void *) (long int) (depth + 1), NULL)) goto fail; if (idx + 1 == (int) pow(2, height + 1)) break; idx++; } printf("\n"); fail: linklist_delete(list); }
void *ar_new(t_symbol *name, long size){ t_ar *x; if(x = (t_ar *)object_alloc(ar_class)){ t_hashtab *ht; t_linklist *ll; x->outlets[3] = outlet_new(x, NULL); x->outlets[2] = outlet_new(x, NULL); x->outlets[1] = outlet_new(x, NULL); x->outlets[0] = outlet_new(x, NULL); if(strlen(name->s_name) > 0){ x->name = name; x->iname_ht = ar_make_iname(name, _sym_hashtab); x->iname_ll = ar_make_iname(name, _sym_linklist); ar_inc_refcount(x->name); if(ht = (t_hashtab *)(name->s_thing)){ }else{ ht = (t_hashtab *)hashtab_new(size); x->iname_ht->s_thing = (t_object *)ht; ll = (t_linklist *)linklist_new(); x->iname_ll->s_thing = (t_object *)ll; } }else{ x->name = ar_make_def_name(); x->iname_ht = ar_make_iname(x->name, _sym_hashtab); x->iname_ll = ar_make_iname(x->name, _sym_linklist); ar_inc_refcount(x->name); /* x->name = _sym_emptytext; x->iname_ht = _sym_emptytext; x->iname_ll = _sym_emptytext; */ } srand(makeseed()); return x; } return NULL; }
void ar_array(t_ar *x, t_symbol *name){ t_symbol *iname_ht = ar_make_iname(name, _sym_hashtab); t_hashtab *incoming_ht = (t_hashtab *)(iname_ht->s_thing); t_hashtab *ht; t_linklist *ll; t_symbol **keys = NULL; long numKeys = 0; long i; hashtab_getkeys(incoming_ht, &numKeys, &keys); if(!(ht = (t_hashtab *)x->iname_ht->s_thing) || !(ll = (t_linklist *)x->iname_ll->s_thing)){ ht = hashtab_new(AR_DEFAULT_SLOTS); ll = linklist_new(); x->iname_ht->s_thing = (void *)ht; x->iname_ll->s_thing = (void *)ll; } ar_freeall(ht, ll); for(i = 0; i < numKeys; i++){ t_atombuf *ab1, *ab2; hashtab_lookup(incoming_ht, keys[i], (t_object **)(&ab1)); ab2 = (t_atombuf *)atombuf_new(ab1->a_argc, ab1->a_argv); hashtab_store(ht, keys[i], (t_object *)ab2); linklist_append(ll, keys[i]); } }
t_paramui* paramui_new(t_symbol *s, long argc, t_atom *argv) { t_paramui *x = NULL; t_dictionary *d = NULL; long flags; t_atom a[LISTSIZE+34]; long argLen; //t_max_err err = MAX_ERR_NONE; if(!(d=object_dictionaryarg(argc, argv))) return NULL; if(x = (t_paramui*)object_alloc(s_ui_class)){ flags = 0 | JBOX_DRAWFIRSTIN | JBOX_NODRAWBOX // | JBOX_DRAWINLAST | JBOX_TRANSPARENT // | JBOX_NOGROW // | JBOX_GROWY // | JBOX_GROWBOTH // | JBOX_IGNORELOCKCLICK | JBOX_HILITE // | JBOX_BACKGROUND // | JBOX_NOFLOATINSPECTOR | JBOX_TEXTFIELD ; jbox_new(&x->box, flags, argc, argv); x->box.b_firstin = (t_object *)x; x->outlet = outlet_new(x, 0L); x->menu_items = NULL; attr_dictionary_process(x, d); // handle attribute args // a textlayout is used for the displaying the value and the unit x->layout_value = jtextlayout_create(); x->layout_unit = jtextlayout_create(); jbox_ready(&x->box); x = (t_paramui *)object_register(CLASS_BOX, symbol_unique(), x); x->menu_items = (t_linklist *)linklist_new(); paramui_menu_build(x); x->menu_qelem = qelem_new(x, (method)paramui_menu_qfn); // here we create our internal instance of jcom.parameter atom_setsym(a+0, x->attr_name); atom_setsym(a+1, gensym("@type")); atom_setsym(a+2, x->attr_type); atom_setsym(a+3, gensym("@ramp/drive")); atom_setsym(a+4, x->attr_rampDrive); atom_setsym(a+5, gensym("@ramp/function")); atom_setsym(a+6, x->attr_rampFunction); atom_setsym(a+7, gensym("@view/freeze")); atom_setlong(a+8, x->attr_uiFreeze); atom_setsym(a+9, gensym("@value/stepsize")); atom_setfloat(a+10, x->attr_stepsize); atom_setsym(a+11, gensym("@priority")); atom_setlong(a+12, x->attr_priority); atom_setsym(a+13, gensym("@range/bounds")); atom_setfloat(a+14, x->attr_range[0]); atom_setfloat(a+15, x->attr_range[1]); atom_setsym(a+16, gensym("@repetitions/allow")); atom_setlong(a+17, x->attr_repetitions); atom_setsym(a+18, gensym("@range/clipmode")); atom_setsym(a+19, x->attr_clipmode); atom_setsym(a+20, gensym("@description")); atom_setsym(a+21, x->attr_description); atom_setsym(a+22, gensym("@dataspace")); atom_setsym(a+23, x->attr_dataspace); atom_setsym(a+24, gensym("@dataspace/unit/active")); atom_setsym(a+25, x->attr_unitActive); atom_setsym(a+26, gensym("@dataspace/unit/native")); atom_setsym(a+27, x->attr_unitNative); if(x->attr_defaultSize){ atom_setsym(a+28, gensym("@value/default")); sysmem_copyptr(x->attr_default, a+29, sizeof(t_atom) * x->attr_defaultSize); argLen = 29 + x->attr_defaultSize; } else argLen = 28; jcom_core_loadextern(gensym("jcom.parameter"), argLen, a, &x->obj_parameter); } return x; }