+struct ovsdb_o_column {
+ const struct ovsdb_column *column;
+ struct hmap o_clauses;
+};
+
+struct ovsdb_o_clause {
+ struct ovsdb_datum *arg;
+ struct hmap_node hmap_node;
+};
+
+static void
+ovsdb_condition_optimize(struct ovsdb_condition *cnd)
+{
+ size_t i;
+ uint32_t hash;
+
+ if (!cnd->optimized) {
+ return;
+ }
+
+ for(i = 0; i < cnd->n_clauses; i++) {
+ struct ovsdb_clause *clause = &cnd->clauses[i];
+
+ if (clause->function != OVSDB_F_EQ) {
+ continue;
+ }
+
+ struct ovsdb_o_clause *o_clause = xzalloc(sizeof *o_clause);
+ struct ovsdb_o_column *o_column =
+ shash_find_data(&cnd->o_columns, clause->column->name);
+
+ if (!o_column) {
+ o_column = xzalloc(sizeof *o_column);
+ o_column->column = clause->column;
+ hmap_init(&o_column->o_clauses);
+ shash_add(&cnd->o_columns, clause->column->name, o_column);
+ }
+ o_clause->arg = &clause->arg;
+ hash = ovsdb_datum_hash(&clause->arg, &clause->column->type, 0);
+ hmap_insert(&o_column->o_clauses, &o_clause->hmap_node, hash);
+ }
+}
+
+static void
+ovsdb_condition_optimize_destroy(struct ovsdb_condition *cnd)
+{
+ struct shash_node *node, *next;
+
+ SHASH_FOR_EACH_SAFE (node, next, &cnd->o_columns) {
+ struct ovsdb_o_column *o_column = node->data;
+ struct ovsdb_o_clause *c, *c_next;
+
+ HMAP_FOR_EACH_SAFE(c, c_next, hmap_node, &o_column->o_clauses) {
+ hmap_remove(&o_column->o_clauses, &c->hmap_node);
+ free(c);
+ }
+ hmap_destroy(&o_column->o_clauses);
+ shash_delete(&cnd->o_columns, node);
+ free(o_column);
+ }
+ shash_destroy(&cnd->o_columns);
+}
+