gboolean gtk_css_node_declaration_equal (gconstpointer elem1, gconstpointer elem2) { const GtkCssNodeDeclaration *decl1 = elem1; const GtkCssNodeDeclaration *decl2 = elem2; GQuark *classes1, *classes2; GtkRegion *regions1, *regions2; guint i; if (decl1 == decl2) return TRUE; if (decl1->type != decl2->type) return FALSE; if (decl1->name != decl2->name) return FALSE; if (decl1->state != decl2->state) return FALSE; if (decl1->id != decl2->id) return FALSE; if (decl1->n_classes != decl2->n_classes) return FALSE; classes1 = get_classes (decl1); classes2 = get_classes (decl2); for (i = 0; i < decl1->n_classes; i++) { if (classes1[i] != classes2[i]) return FALSE; } if (decl1->n_regions != decl2->n_regions) return FALSE; regions1 = get_regions (decl1); regions2 = get_regions (decl2); for (i = 0; i < decl1->n_regions; i++) { if (regions1[i].class_quark != regions2[i].class_quark || regions1[i].flags != regions2[i].flags) return FALSE; } if (decl1->junction_sides != decl2->junction_sides) return FALSE; return TRUE; }
void gtk_css_node_declaration_add_to_widget_path (const GtkCssNodeDeclaration *decl, GtkWidgetPath *path, guint pos) { GQuark *classes; GtkRegion *regions; guint i; /* Set name and id */ gtk_widget_path_iter_set_object_name (path, pos, decl->name); if (decl->id) gtk_widget_path_iter_set_name (path, pos, decl->id); /* Set widget regions */ regions = get_regions (decl); for (i = 0; i < decl->n_regions; i++) { G_GNUC_BEGIN_IGNORE_DEPRECATIONS gtk_widget_path_iter_add_region (path, pos, g_quark_to_string (regions[i].class_quark), regions[i].flags); G_GNUC_END_IGNORE_DEPRECATIONS } /* Set widget classes */ classes = get_classes (decl); for (i = 0; i < decl->n_classes; i++) { gtk_widget_path_iter_add_qclass (path, pos, classes[i]); } /* Set widget state */ gtk_widget_path_iter_set_state (path, pos, decl->state); }
gboolean gtk_css_node_declaration_has_class (const GtkCssNodeDeclaration *decl, GQuark class_quark) { guint pos; GQuark *classes = get_classes (decl); switch (decl->n_classes) { case 3: if (classes[2] == class_quark) return TRUE; case 2: if (classes[1] == class_quark) return TRUE; case 1: if (classes[0] == class_quark) return TRUE; case 0: return FALSE; default: return find_class (decl, class_quark, &pos); } }
guint gtk_css_node_declaration_hash (gconstpointer elem) { const GtkCssNodeDeclaration *decl = elem; GQuark *classes; GtkRegion *regions; guint hash, i; hash = (guint) decl->type; hash ^= GPOINTER_TO_UINT (decl->name); hash <<= 5; hash ^= GPOINTER_TO_UINT (decl->id); classes = get_classes (decl); for (i = 0; i < decl->n_classes; i++) { hash <<= 5; hash += classes[i]; } regions = get_regions (decl); for (i = 0; i < decl->n_regions; i++) { hash <<= 5; hash += regions[i].class_quark; hash += regions[i].flags; } hash ^= ((guint) decl->junction_sides) << (sizeof (guint) * 8 - 5); hash ^= decl->state; return hash; }
PyObject* info( int type, const char *name) { PyObject* output = NULL; switch(type) { /* display requested info */ case TYPE: output = get_types(name, policy); break; case ATTRIBUTE: output = get_attribs(name, policy); break; case ROLE: output = get_roles(name, policy); break; case USER: output = get_users(name, policy); break; case CLASS: output = get_classes(name, policy); break; case BOOLEAN: output = get_booleans(name, policy); break; case PORT: output = get_ports(name, policy); break; default: errno = EINVAL; PyErr_SetString(PyExc_RuntimeError,strerror(errno)); break; } return output; }
const GQuark * gtk_css_node_declaration_get_classes (const GtkCssNodeDeclaration *decl, guint *n_classes) { *n_classes = decl->n_classes; return get_classes (decl); }
gboolean gtk_css_node_declaration_add_class (GtkCssNodeDeclaration **decl, GQuark class_quark) { guint pos; if (find_class (*decl, class_quark, &pos)) return FALSE; gtk_css_node_declaration_make_writable_resize (decl, (char *) &get_classes (*decl)[pos] - (char *) *decl, sizeof (GQuark), 0); (*decl)->n_classes++; get_classes(*decl)[pos] = class_quark; return TRUE; }
gboolean gtk_css_node_declaration_clear_classes (GtkCssNodeDeclaration **decl) { if ((*decl)->n_classes == 0) return FALSE; gtk_css_node_declaration_make_writable_resize (decl, (char *) get_classes (*decl) - (char *) *decl, 0, sizeof (GQuark) * (*decl)->n_classes); (*decl)->n_classes = 0; return TRUE; }
/* Append the declaration to the string, in selector format */ void gtk_css_node_declaration_print (const GtkCssNodeDeclaration *decl, GString *string) { static const char *state_names[] = { "active", "hover", "selected", "disabled", "indeterminate", "focus", "backdrop", "dir(ltr)", "dir(rtl)", "link", "visited", "checked", "drop(active)" }; const GQuark *classes; guint i; if (decl->name) g_string_append (string, decl->name); else g_string_append (string, g_type_name (decl->type)); if (decl->id) { g_string_append_c (string, '#'); g_string_append (string, decl->id); } classes = get_classes (decl); for (i = 0; i < decl->n_classes; i++) { g_string_append_c (string, '.'); g_string_append (string, g_quark_to_string (classes[i])); } for (i = 0; i < G_N_ELEMENTS (state_names); i++) { if (decl->state & (1 << i)) { g_string_append_c (string, ':'); g_string_append (string, state_names[i]); } } }
void Dectree_class::train(const cv::Mat& training_data, const cv::Mat& labels, int depth_thresh, unsigned int samples_thresh) { //determine the number of classes based on the training data get_classes(labels); //std::cout << "Classes:\n" << classes << std::endl; //make a vector giving an id to each attribute set_attributes(training_data); //for debbugging /* for(std::vector<int>::iterator it = attributes.begin(); it != attributes.end(); ++it) std::cout << *it << " "; std::cout << std::endl; */ //compute the initial impurity just fot debugging //double hgoal = compute_entropy(labels); //std::cout << "Initial entropy: " << hgoal << std::endl; //grow a decision tree depth_limit = depth_thresh; min_samples = samples_thresh; int depth = 1; dbst.set_root(learn_dectree(cv::Mat(),labels, training_data, attributes, depth)); find_depth(dbst.get_root()); std::cout << "min depth: " << min_depth << std::endl; //for debugging //print the obtained tree /* std::cout<< "\ninOrder traversal: " << std::endl; dbst.inOrder(dbst.get_root()); std::cout << std::endl; std::cout<< "\npostOrder traversal: " << std::endl; dbst.postOrder(dbst.get_root()); std::cout << std::endl; */ //only for testing /* int a = plurality(labels); std::cout << "Best class: " << a << std::endl; bool b = check_classif(labels); std::cout << "All same class?: " << b << std::endl; dectree_split* t = best_split(attributes, training_data, labels); std::cout << "Best attr: " << t->attr_name << " Pos: " << t->attr_idx << std::endl; std::cout << t->neg_attr_labels << std::endl; std::cout << t->neg_attr_data << std::endl; std::cout << t->pos_attr_labels << std::endl; std::cout << t->pos_attr_data << std::endl; */ }
static gboolean find_class (const GtkCssNodeDeclaration *decl, GQuark class_quark, guint *position) { gint min, max, mid; gboolean found = FALSE; GQuark *classes; guint pos; *position = 0; if (decl->n_classes == 0) return FALSE; min = 0; max = decl->n_classes - 1; classes = get_classes (decl); do { GQuark item; mid = (min + max) / 2; item = classes[mid]; if (class_quark == item) { found = TRUE; pos = mid; break; } else if (class_quark > item) min = pos = mid + 1; else { max = mid - 1; pos = mid; } } while (min <= max); *position = pos; return found; }
static inline GtkRegion * get_regions (const GtkCssNodeDeclaration *decl) { return (GtkRegion *) (get_classes (decl) + decl->n_classes); }