libsnobol4 1.0.2
High-performance SNOBOL4-style pattern matching library
Loading...
Searching...
No Matches
dynamic_pattern.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7
8#include <stdbool.h>
9#include "snobol/c23_compat.h"
10#include <stddef.h>
11#include <stdint.h>
12
63
64/* Forward declarations */
66
73typedef struct dynamic_pattern {
74 uint8_t *bc; /* Owned: compiled bytecode */
75 size_t bc_len; /* Length of bytecode */
76 char *source; /* Owned: original source string (for debugging) */
77 uint32_t refcount; /* Reference count */
78 uint32_t hash; /* Pre-computed hash of source for caching */
79 bool is_valid; /* Pattern compiled successfully */
81
88typedef struct {
89 uint32_t hash; /* Hash of source content */
90 size_t source_len; /* Length of source */
91 /* The actual source bytes follow this struct in memory */
93
98 uint32_t hash; /* Hash for quick lookup */
99 char *source; /* Owned: source string */
100 dynamic_pattern_t *pattern; /* Owned reference */
101 struct dynamic_pattern_cache_entry *next; /* Next in bucket */
103
110typedef struct {
112 size_t bucket_count; /* Number of buckets */
113 size_t size; /* Number of entries */
114 size_t max_size; /* Maximum entries before eviction */
116
128dynamic_pattern_t *dynamic_pattern_create(const char *source, uint8_t *bc,
129 size_t bc_len);
130
137
143
152 const char *source, size_t source_len,
154
162 size_t max_size);
163
169
180 const char *source,
181 int source_len);
182
193 const char *source, dynamic_pattern_t *pattern);
194
203 const char *source, int source_len);
204
210
218 size_t *out_size, size_t *out_max);
219
226uint32_t dynamic_pattern_hash_source(const char *source, size_t len);
227
228#ifdef __cplusplus
229}
230#endif
void dynamic_pattern_release(dynamic_pattern_t *pattern)
Decrement reference count and free if zero.
dynamic_pattern_t * dynamic_pattern_cache_get(dynamic_pattern_cache_t *cache, const char *source, int source_len)
Look up a pattern in the cache.
dynamic_pattern_t * dynamic_pattern_create(const char *source, uint8_t *bc, size_t bc_len)
Create a new dynamic pattern object.
struct dynamic_pattern dynamic_pattern_t
void dynamic_pattern_cache_stats(const dynamic_pattern_cache_t *cache, size_t *out_size, size_t *out_max)
Get cache statistics.
void dynamic_pattern_cache_clear(dynamic_pattern_cache_t *cache)
Clear all entries from the cache.
bool dynamic_pattern_cache_remove(dynamic_pattern_cache_t *cache, const char *source, int source_len)
Remove a pattern from the cache.
uint32_t dynamic_pattern_hash_source(const char *source, size_t len)
Hash function for pattern sources.
const dynamic_pattern_cache_key_t * dynamic_pattern_compute_key(const char *source, size_t source_len, dynamic_pattern_cache_key_t *out_key)
Compute canonical cache key from source string.
void dynamic_pattern_cache_destroy(dynamic_pattern_cache_t *cache)
Destroy cache and free all entries.
struct dynamic_pattern_cache_entry dynamic_pattern_cache_entry_t
bool dynamic_pattern_cache_init(dynamic_pattern_cache_t *cache, size_t max_size)
Initialize dynamic pattern cache.
dynamic_pattern_t * dynamic_pattern_retain(dynamic_pattern_t *pattern)
Increment dynamic pattern reference count.
struct snobol_table snobol_table_t
Associative table (opaque handle).
bool dynamic_pattern_cache_put(dynamic_pattern_cache_t *cache, const char *source, dynamic_pattern_t *pattern)
Insert a pattern into the cache.
dynamic_pattern_t * pattern
uint32_t hash
struct dynamic_pattern_cache_entry * next
char * source
dynamic_pattern_cache_entry_t ** buckets