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