1 /* vifm 2 * Copyright (C) 2015 xaizek. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 */ 18 19 #ifndef VIFM__UTILS__TRIE_H__ 20 #define VIFM__UTILS__TRIE_H__ 21 22 #include <stddef.h> /* NULL */ 23 24 /* Declaration of opaque trie type. */ 25 typedef struct trie_t trie_t; 26 27 /* Type of function to free data in the trie via trie_free_with_data() . */ 28 typedef void (*trie_free_func)(void *ptr); 29 30 /* Creates new empty trie. Returns NULL on error. */ 31 trie_t * trie_create(void); 32 33 /* Clones a trie. Associated data pointers are copied as is. Returns NULL on 34 * error. */ 35 trie_t * trie_clone(trie_t *trie); 36 37 /* Frees memory allocated for the trie. Freeing of NULL trie is OK. */ 38 void trie_free(trie_t *trie); 39 40 /* Frees memory allocated for the trie. Freeing of NULL trie is OK. All data 41 * associated with trie entries is freed by calling free_func() on it. */ 42 void trie_free_with_data(trie_t *trie, trie_free_func free_func); 43 44 /* Inserts string to the trie if it's not already there. Returns negative value 45 * on error, zero on successful insertion and positive number if element was 46 * already in the trie. */ 47 int trie_put(trie_t *trie, const char str[]); 48 49 /* Same as trie_put(), but also sets data. */ 50 int trie_set(trie_t *trie, const char str[], const void *data); 51 52 /* Looks up data for the str in the trie. trie can be NULL, which is treated as 53 * an empty trie. Returns zero when found and sets *data, otherwise returns 54 * non-zero. */ 55 int trie_get(trie_t *trie, const char str[], void **data); 56 57 #endif /* VIFM__UTILS__TRIE_H__ */ 58 59 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */ 60 /* vim: set cinoptions+=t0 filetype=c : */ 61