diff options
Diffstat (limited to 'examples/dte/history.h')
| -rw-r--r-- | examples/dte/history.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/dte/history.h b/examples/dte/history.h new file mode 100644 index 0000000..12073f5 --- /dev/null +++ b/examples/dte/history.h | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | #ifndef HISTORY_H | ||
| 2 | #define HISTORY_H | ||
| 3 | |||
| 4 | #include <stdbool.h> | ||
| 5 | #include <stddef.h> | ||
| 6 | #include "util/hashmap.h" | ||
| 7 | #include "util/macros.h" | ||
| 8 | |||
| 9 | typedef struct HistoryEntry { | ||
| 10 | struct HistoryEntry *next; | ||
| 11 | struct HistoryEntry *prev; | ||
| 12 | char *text; | ||
| 13 | } HistoryEntry; | ||
| 14 | |||
| 15 | // This is a HashMap with a doubly-linked list running through the | ||
| 16 | // entries, in a way similar to the Java LinkedHashMap class. The | ||
| 17 | // HashMap allows duplicates to be found and re-inserted at the end | ||
| 18 | // of the list in O(1) time and the doubly-linked entries allow | ||
| 19 | // ordered traversal. | ||
| 20 | typedef struct { | ||
| 21 | char *filename; | ||
| 22 | HashMap entries; | ||
| 23 | HistoryEntry *first; | ||
| 24 | HistoryEntry *last; | ||
| 25 | size_t max_entries; | ||
| 26 | } History; | ||
| 27 | |||
| 28 | void history_add(History *history, const char *text); | ||
| 29 | bool history_search_forward(const History *history, const HistoryEntry **pos, const char *text) WARN_UNUSED_RESULT; | ||
| 30 | bool history_search_backward(const History *history, const HistoryEntry **pos, const char *text) WARN_UNUSED_RESULT; | ||
| 31 | void history_load(History *history, char *filename); | ||
| 32 | void history_save(const History *history); | ||
| 33 | void history_free(History *history); | ||
| 34 | |||
| 35 | #endif | ||
