decrypt drsuapi attributes
[wireshark-sm.git] / epan / fifo_string_cache.h
blob09cb6150aa24b4401edc28b062180cb31d2a32b6
1 /* fifo_string_cache.h
2 * A string cache, possibly with a bounded size, using FIFO order to control
3 * the size.
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
11 #ifndef __FIFO_STRING_CACHE_H__
12 #define __FIFO_STRING_CACHE_H__
14 #include <stdbool.h>
16 #include <glib.h>
18 #include "ws_symbol_export.h"
20 #ifdef __cplusplus
21 extern "C" {
22 #endif /* __cplusplus */
24 typedef struct {
25 GHashTable *set;
26 GSList *head;
27 GSList *tail;
28 unsigned max_entries;
29 } fifo_string_cache_t;
31 // These functions are marked with WS_DLL_PUBLIC so they can be unit-tested
33 // Initialize an object. If string_free_func is given, then the
34 // fifo_string_cache owns the string data, and will call this string_free_func
35 // during fifo_string_cache_free().
36 // If string_free_func is NULL, then the caller owns the string data, and it is
37 // the caller that is responsible for freeing the data.
38 WS_DLL_PUBLIC void
39 fifo_string_cache_init(fifo_string_cache_t *fcache, unsigned max_entries, GDestroyNotify string_free_func);
41 // Free all memory owned by the fifo_string_cache. Whether or not the
42 // fifoe_string_cache owns the actual strings depends on whether a
43 // string_free_func was passed in during fifo_string_cache_init().
44 WS_DLL_PUBLIC void
45 fifo_string_cache_free(fifo_string_cache_t *fcache);
47 // Does the cache contain a specific string?
48 WS_DLL_PUBLIC bool
49 fifo_string_cache_contains(fifo_string_cache_t *fcache, const char *entry);
51 // Insert a string. The return value indicates whether the string was already
52 // in the cache before this function was called. If the string was newly
53 // inserted, and max_entries is > 0, and inserting the string would have caused
54 // max_entries to be exceeded, the oldest inserted key is removed (FIFO order).
55 WS_DLL_PUBLIC bool
56 fifo_string_cache_insert(fifo_string_cache_t *fcache, const char *entry);
58 #ifdef __cplusplus
60 #endif /* __cplusplus */
62 #endif /* __FIFO_STRING_CACHE_H__ */