-#define vec_free(A) ((A) ? (mem_d(_vec_raw(A)), (A) = NULL) : 0)
-#define vec_push(A,V) (_vec_mightgrow((A),1), (A)[_vec_end(A)++] = (V))
-#define vec_size(A) ((A) ? _vec_end(A) : 0)
-#define vec_add(A,N) (_vec_mightgrow((A),(N)), _vec_end(A)+=(N), &(A)[_vec_end(A)-(N)])
-#define vec_last(A) ((A)[_vec_end(A)-1])
-#define vec_append(A,N,S) memcpy(vec_add((A), (N)), (S), N * sizeof(*(S)))
-#define vec_remove(A,I,N) _vec_remove((A), sizeof(*(A)), (I), (N))
-#define vec_pop(A) vec_remove((A), _vec_end(A)-1, 1)
-/* these are supposed to NOT reallocate */
-#define vec_shrinkto(A,N) (_vec_end(A) = (N))
-#define vec_shrinkby(A,N) (_vec_end(A) -= (N))
+#define vec_meta(A) (((vector_t*)((void*)A)) - 1)
+#define vec_free(A) ((void)((A) ? (mem_d((void*)vec_meta(A)), (A) = NULL) : 0))
+#define vec_push(A,V) (GMQCC_VEC_WILLGROW((A),1), (A)[vec_meta(A)->used++] = (V))
+#define vec_size(A) ((A) ? vec_meta(A)->used : 0)
+#define vec_add(A,N) (GMQCC_VEC_WILLGROW((A),(N)), vec_meta(A)->used += (N), &(A)[vec_meta(A)->used-(N)])
+#define vec_last(A) ((A)[vec_meta(A)->used - 1])
+#define vec_pop(A) ((void)(vec_meta(A)->used -= 1))
+#define vec_shrinkto(A,N) ((void)(vec_meta(A)->used = (N)))
+#define vec_shrinkby(A,N) ((void)(vec_meta(A)->used -= (N)))
+#define vec_append(A,N,S) ((void)(memcpy(vec_add((A), (N)), (S), (N) * sizeof(*(S)))))
+#define vec_remove(A,I,N) ((void)(memmove((A)+(I),(A)+((I)+(N)),sizeof(*(A))*(vec_meta(A)->used-(I)-(N))),vec_meta(A)->used-=(N)))
+
+typedef struct correct_trie_s {
+ void *value;
+ struct correct_trie_s *entries;
+} correct_trie_t;
+
+correct_trie_t* correct_trie_new(void);
+
+typedef struct hash_table_s {
+ size_t size;
+ struct hash_node_t **table;
+} hash_table_t, *ht;
+
+/*
+ * hashtable implementation:
+ *
+ * Note:
+ * This was designed for pointers: you manage the life of the object yourself
+ * if you do use this for non-pointers please be warned that the object may not
+ * be valid if the duration of it exceeds (i.e on stack). So you need to allocate
+ * yourself, or put those in global scope to ensure duration is for the whole
+ * runtime.
+ *
+ * util_htnew(size) -- to make a new hashtable
+ * util_htset(table, key, value, sizeof(value)) -- to set something in the table
+ * util_htget(table, key) -- to get something from the table
+ * util_htdel(table) -- to delete the table
+ *
+ * example of use:
+ *
+ * ht foo = util_htnew(1024);
+ * int data = 100;
+ * char *test = "hello world\n";
+ * util_htset(foo, "foo", (void*)&data);
+ * util_gtset(foo, "bar", (void*)test);
+ *
+ * printf("foo: %d, bar %s",
+ * *((int *)util_htget(foo, "foo")),
+ * ((char*)util_htget(foo, "bar"))
+ * );
+ *
+ * util_htdel(foo);
+ */
+hash_table_t *util_htnew (size_t size);
+void util_htrem (hash_table_t *ht, void (*callback)(void *data));
+void util_htset (hash_table_t *ht, const char *key, void *value);
+void util_htdel (hash_table_t *ht);
+size_t util_hthash(hash_table_t *ht, const char *key);
+void util_htseth(hash_table_t *ht, const char *key, size_t hash, void *value);
+void util_htrmh (hash_table_t *ht, const char *key, size_t bin, void (*cb)(void*));
+void util_htrm (hash_table_t *ht, const char *key, void (*cb)(void*));
+
+void *util_htget (hash_table_t *ht, const char *key);
+void *util_htgeth(hash_table_t *ht, const char *key, size_t hash);
+
+/*===================================================================*/
+/*============================ file.c ===============================*/
+/*===================================================================*/
+/* file handling */
+void fs_file_close (FILE *);
+int fs_file_error (FILE *);
+int fs_file_getc (FILE *);
+int fs_file_printf (FILE *, const char *, ...);
+int fs_file_puts (FILE *, const char *);
+int fs_file_seek (FILE *, long int, int);
+long int fs_file_tell (FILE *);
+
+size_t fs_file_read (void *, size_t, size_t, FILE *);
+size_t fs_file_write (const void *, size_t, size_t, FILE *);
+
+FILE *fs_file_open (const char *, const char *);
+int fs_file_getline(char **, size_t *, FILE *);
+
+/* directory handling */
+int fs_dir_make (const char *);
+DIR *fs_dir_open (const char *);
+int fs_dir_close (DIR *);
+struct dirent *fs_dir_read (DIR *);
+
+
+/*===================================================================*/
+/*=========================== correct.c =============================*/
+/*===================================================================*/
+typedef struct {
+ char ***edits;
+ size_t **lens;
+} correction_t;
+
+void correct_del (correct_trie_t*, size_t **);
+void correct_add (correct_trie_t*, size_t ***, const char *);
+char *correct_str (correction_t *, correct_trie_t*, const char *);
+void correct_init(correction_t *);
+void correct_free(correction_t *);