void ofl_structs_oxm_match_print(FILE *stream, const struct ofl_match *omt) { struct ofl_match_tlv *f; int i; size_t size; if(omt->header.length > 4) size = hmap_count(&omt->match_fields); else size = 0; fprintf(stream, "oxm{"); if (size) { /* Iterate over all possible OXM fields in their natural order */ for (i = 0; i<NUM_OXM_FIELDS; i++) { f = oxm_match_lookup(all_fields[i].header, omt); if (f != NULL) { /* Field present: print it */ ofl_structs_oxm_tlv_print(stream, f); if (--size > 0) fprintf(stream, ", "); } } } else { fprintf(stream, "all match"); } fprintf(stream, "}"); }
int main(int argc, char **argv) { struct hmap *map = malloc(sizeof(*map)); hmap_init(map); struct hmap_node node2 = {1, NULL}; hmap_insert_fast(map, &nodes[0].node, strlen(nodes[0].key)); hmap_insert_fast(map, &nodes[1].node, strlen(nodes[1].key)); struct nd *q; //HMAP_FOR_EACH(q, node, map) { // printf("key= %s",q->key); //} printf("map size %lu, capacity %lu\n", hmap_count(map), hmap_capacity(map)); hmap_destroy(map); }
// Test remove function int test_hmap_3() { hmap_handle* hmap; hmap = hmap_create(); int* data1; int* data2; int* data3; data1 = new(int); *data1 = 0; hmap_put(hmap, (long) (*data1), data1); data2 = new(int); *data2 = 1; hmap_put(hmap, (long) (*data2), data2); data3 = new(int); *data3 = 2; hmap_put(hmap, (long) (*data3), data3); int* tmp1 = hmap_remove(hmap, (long) (*data1)); int* tmp2 = hmap_remove(hmap, (long) (*data2)); int* tmp3 = hmap_remove(hmap, (long) (*data3)); if (tmp1 != data1 || tmp2 != data2 || tmp3 != data3 || hmap_count(hmap) != 0) { kfree(tmp1); kfree(tmp2); kfree(tmp3); hmap_free(hmap); return TEST_FAIL; } kfree(tmp1); kfree(tmp2); kfree(tmp3); hmap_free(hmap); return TEST_OK; }
/* Returns the number of attributes in SET. */ size_t attrset_count (const struct attrset *set) { return hmap_count (&set->map); }
// Test count function int test_hmap_4() { hmap_handle* hmap; hmap = hmap_create(); int* data1; int* data2; int* data3; int* data4; data1 = new(int); *data1 = 0; hmap_put(hmap, (long) (*data1), data1); if (hmap_count(hmap) != 1) { kfree(data1); hmap_free(hmap); return TEST_FAIL; } data2 = new(int); *data2 = 1; hmap_put(hmap, (long) (*data2), data2); if (hmap_count(hmap) != 2) { kfree(data1); kfree(data2); hmap_free(hmap); return TEST_FAIL; } data3 = new(int); *data3 = 2; hmap_put(hmap, (long) (*data3), data3); if (hmap_count(hmap) != 3) { kfree(data1); kfree(data2); kfree(data3); hmap_free(hmap); return TEST_FAIL; } kfree(hmap_remove(hmap, (long) (*data2))); if (hmap_count(hmap) != 2) { kfree(data1); kfree(data3); hmap_free(hmap); return TEST_FAIL; } data4 = new(int); *data4 = 3; hmap_put(hmap, (long) (*data4), data4); if (hmap_count(hmap) != 3) { kfree(data1); kfree(data3); kfree(data4); hmap_free(hmap); return TEST_FAIL; } kfree(data1); kfree(data2); kfree(data3); kfree(data4); hmap_free(hmap); return TEST_OK; }