+// ------------------------------- mtf_t --------------------------------------
+mtf_t* mtf_new(type_t*type)
+{
+ NEW(mtf_t, mtf);
+ mtf->type = type;
+ return mtf;
+}
+void mtf_increase(mtf_t*m, const void*key)
+{
+ mtf_item_t*item = m->first;
+ mtf_item_t*last = 0;
+ while(item) {
+ if(m->type->equals(item->key, key)) {
+ item->num++;
+ if(item->num>m->first->num) {
+ if(last) last->next = item->next;
+ else m->first = item->next;
+ item->next = m->first;
+ m->first = item;
+ }
+ return;
+ }
+ last = item;
+ item = item->next;
+ }
+ NEW(mtf_item_t,n);
+ if(last) last->next = n;
+ else m->first = n;
+ n->key = key;
+ n->num = 1;
+}
+void mtf_destroy(mtf_t*m)
+{
+ if(!m) return;
+ mtf_item_t*item = m->first;
+ m->first = 0;
+ while(item) {
+ mtf_item_t*next = item->next;
+ item->next = 0;
+ free(item);
+ item = next;
+ }
+ free(m);
+}
+