From 1566b6faa8534118c3566188181367cd0868468f Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Thu, 9 Nov 2023 23:19:53 +0100 Subject: Added partial matching and introduced threads --- examples/dte/history.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 examples/dte/history.h (limited to 'examples/dte/history.h') 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 @@ +#ifndef HISTORY_H +#define HISTORY_H + +#include +#include +#include "util/hashmap.h" +#include "util/macros.h" + +typedef struct HistoryEntry { + struct HistoryEntry *next; + struct HistoryEntry *prev; + char *text; +} HistoryEntry; + +// This is a HashMap with a doubly-linked list running through the +// entries, in a way similar to the Java LinkedHashMap class. The +// HashMap allows duplicates to be found and re-inserted at the end +// of the list in O(1) time and the doubly-linked entries allow +// ordered traversal. +typedef struct { + char *filename; + HashMap entries; + HistoryEntry *first; + HistoryEntry *last; + size_t max_entries; +} History; + +void history_add(History *history, const char *text); +bool history_search_forward(const History *history, const HistoryEntry **pos, const char *text) WARN_UNUSED_RESULT; +bool history_search_backward(const History *history, const HistoryEntry **pos, const char *text) WARN_UNUSED_RESULT; +void history_load(History *history, char *filename); +void history_save(const History *history); +void history_free(History *history); + +#endif -- cgit v1.2.3