os_int32 ut_walk( ut_collection c, const ut_actionFunc action, void *arg) { os_int32 succes; assert(c); assert(action); succes = 0; switch (c->type) { case UT_TABLE : { OS_STRUCT(ut_tableWalkActionArg) args; args.tableActionFunc = action; args.actionArg = arg; args.collection = c; succes = ut_avlTreeWalk(ut_table(c)->tree, ut_tableActionWrapper, &args, UT_PREFIX); } break; default : fprintf(stderr, "ut_walk: This collection type is not yet supported\n"); assert(0); break; } return succes; }
os_int32 ut_tableInsert( ut_table t, void *key, void *value) { os_int32 returnValue; void *treeValue; ut_tableNode node; returnValue = 0; treeValue = NULL; node = NULL; assert(ut_collection(t)->type == UT_TABLE); node = ut_newTableNode(key, value); treeValue = ut_avlTreeInsert(ut_table(t)->tree, node, ut_tableCmpWrapper, (void *)t); if (treeValue == node) { returnValue = 1; } else { os_free(node); } return returnValue; }
static refLeaf monitor_typeExtent ( c_type o, monitor_trc trace ) { refLeaf ted = NULL; ted = (refLeaf)ut_get (trace->extTree, o); if (ted) { if (ted->cycleNr != trace->cycleNr) { ted->ecp = ted->ec; ted->ec = o->objectCount; ted->cycleNr = trace->cycleNr; } } else { ted = malloc (C_SIZEOF(refLeaf)); ted->tr = o; ted->ec = o->objectCount; ted->ecp = 0; ted->cycleNr = trace->cycleNr; ut_tableInsert(ut_table(trace->extTree), o, ted); } return ted; }
static void orderedWalk ( c_metaObject o, monitor_trc trace ) { switch (c_baseObject(o)->kind) { case M_MODULE: c_metaWalk (o, orderedWalk, trace); break; case M_UNDEFINED: case M_ATTRIBUTE: case M_CONSTANT: case M_CONSTOPERAND: case M_EXPRESSION: case M_LITERAL: case M_MEMBER: case M_OPERATION: case M_PARAMETER: case M_RELATION: case M_BASE: case M_UNIONCASE: case M_COUNT: break; default: ut_tableInsert(ut_table(trace->orderedList), o, o); break; } }
void * ut_tableNext( ut_table table, void *o) { ut_tableNode node = NULL; ut_tableNode nextNode = NULL; assert(table); node = ut_newTableNode(o, NULL); nextNode = ut_avlTreeNearest(ut_table(table)->tree, node, ut_tableCmpWrapper, (void *)table, OS_GT); os_free(node); return nextNode->value; }
os_int32 ut_contains( ut_collection c, void *o) { os_int32 contains; assert(c); assert(o); contains = 0; switch (c->type) { case UT_TABLE : { ut_tableNode node = NULL; ut_tableNode foundNode = NULL; node = ut_newTableNode(o, NULL); foundNode = ut_avlTreeFind(ut_table(c)->tree, node, ut_tableCmpWrapper, (void *)c); if (foundNode != NULL) { if (OS_EQ == ut_tableCmpWrapper(foundNode, node, c)) { contains = 1; } } os_free(node); } break; default : fprintf(stderr, "ut_contains: This collection type is not yet supported\n"); assert(0); break; } return contains; }
os_int32 ut_count( ut_collection c) { os_int32 count; assert(c); count = -1; switch (c->type) { case UT_TABLE : count = ut_avlTreeCount(ut_table(c)->tree); break; default : fprintf(stderr, "ut_count: This collection type is not yet supported\n"); assert(0); break; } return count; }
void * ut_remove( ut_collection c, void *o) { void *result; assert(c); assert(o); result = NULL; switch (c->type) { case UT_TABLE : { ut_tableNode node = NULL; ut_tableNode foundNode = NULL; node = ut_newTableNode(o, NULL); foundNode = ut_avlTreeRemove (ut_table(c)->tree, node, ut_tableCmpWrapper, (void *)c, NULL, /* removal is allowed */ NULL); os_free(node); if (foundNode) { result = foundNode->value; } } break; default : fprintf(stderr, "ut_remove: This collection type is not yet supported\n"); assert(0); break; } return result; }
static void monitor_object ( c_object o, monitor_orc trace ) { refLeaf ord; c_type tr = c_header(o)->type; if (tr == NULL) { tr = nullType; } ord = (refLeaf)ut_get (trace->refTree, tr); if (ord) { ord->rc++; } else { ord = malloc (C_SIZEOF(refLeaf)); ord->tr = tr; ord->rc = 1; ord->prc = 0; ut_tableInsert(ut_table(trace->refTree), tr, ord); } }