Graphviz 13.0.0~dev.20250121.0651
Loading...
Searching...
No Matches
refstr.c File Reference

API: cgraph.h, cghdr.h. More...

#include <assert.h>
#include <cgraph/cghdr.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <util/alloc.h>
#include <util/unreachable.h>
Include dependency graph for refstr.c:

Go to the source code of this file.

Data Structures

struct  refstr_t
 
struct  strdict_t
 a string dictionary More...
 

Functions

static bool refstr_eq (const char *a, bool is_html, const refstr_t *b)
 
static uint64_t hash (const void *key, size_t len, uint8_t extra)
 
static strdict_tstrdict_new (void)
 create a new string dictionary
 
static size_t strdict_hash (const char *s, bool is_html)
 
static void strdict_add (strdict_t *dict, refstr_t *r)
 add a reference-counted string to a dictionary
 
static refstr_tstrdict_find (strdict_t *dict, const char *s, bool is_html)
 
static void strdict_remove (strdict_t *dict, const refstr_t *key)
 remove a reference-counted string from a dictionary
 
static void strdict_free (strdict_t **dict)
 destroy a string dictionary
 
static strdict_t ** refdict (Agraph_t *g)
 
int agstrclose (Agraph_t *g)
 
static char * refstrbind (strdict_t *strdict, const char *s)
 
char * agstrbind (Agraph_t *g, const char *s)
 
static char * agstrdup_internal (Agraph_t *g, const char *s, bool is_html)
 
char * agstrdup (Agraph_t *g, const char *s)
 returns a pointer to a reference-counted copy of the argument string, creating one if necessary
 
char * agstrdup_html (Agraph_t *g, const char *s)
 
int agstrfree (Agraph_t *g, const char *s, bool is_html)
 
int aghtmlstr (const char *s)
 

Variables

static strdict_tRefdict_default
 
static refstr_t *const TOMBSTONE = (refstr_t *)-1
 

Function Documentation

◆ agstrclose()

int agstrclose ( Agraph_t g)

Definition at line 322 of file refstr.c.

References refdict(), and strdict_free().

Referenced by agclose().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ agstrdup_internal()

static char * agstrdup_internal ( Agraph_t g,
const char *  s,
bool  is_html 
)
static

Definition at line 342 of file refstr.c.

References gv_calloc(), refstr_t::is_html, malloc(), NULL, refstr_t::refcnt, refdict(), refstr_t::s, strdict_add(), and strdict_find().

Referenced by agstrdup(), and agstrdup_html().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hash()

static uint64_t hash ( const void *  key,
size_t  len,
uint8_t  extra 
)
static

derive a hash value from the given data

Parameters
keyStart of data to read
lenNumber of bytes to read
extraAn extra byte to include in the hash
Returns
A hash digest suitable for dictionary indexing

Definition at line 68 of file refstr.c.

References len(), NULL, and seed.

Here is the call graph for this function:

◆ refdict()

static strdict_t ** refdict ( Agraph_t g)
static

Definition at line 309 of file refstr.c.

References Agraph_s::clos, NULL, Refdict_default, Agclos_s::strdict, and strdict_new().

Referenced by agstrbind(), agstrclose(), agstrdup_internal(), and agstrfree().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ refstr_eq()

static bool refstr_eq ( const char *  a,
bool  is_html,
const refstr_t b 
)
static

compare a string to a reference-counted string for equality

Parameters
aContent of the first string
is_htmlWhether the first string was an HTML-like string
bThe second reference-counted string
Returns
True if the two were equal

Definition at line 46 of file refstr.c.

References refstr_t::is_html, and refstr_t::s.

Referenced by strdict_find(), and strdict_remove().

Here is the caller graph for this function:

◆ refstrbind()

static char * refstrbind ( strdict_t strdict,
const char *  s 
)
static

Definition at line 328 of file refstr.c.

References NULL, refstr_t::s, and strdict_find().

Referenced by agstrbind().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strdict_add()

static void strdict_add ( strdict_t dict,
refstr_t r 
)
static

Definition at line 161 of file refstr.c.

References strdict_t::buckets, strdict_t::capacity_exp, free(), gv_calloc(), refstr_t::is_html, NULL, refstr_t::s, strdict_t::size, strdict_add(), strdict_hash(), TOMBSTONE, and UNREACHABLE.

Referenced by agstrdup_internal(), and strdict_add().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strdict_find()

static refstr_t * strdict_find ( strdict_t dict,
const char *  s,
bool  is_html 
)
static

lookup a reference-counted string in a dictionary

Parameters
dictString dictionary to search
sString content to search for
is_htmlIs this an HTML-like string?
Returns
Found reference-counted string, or null if not found

Definition at line 225 of file refstr.c.

References strdict_t::buckets, strdict_t::capacity_exp, NULL, refstr_eq(), strdict_hash(), and TOMBSTONE.

Referenced by agstrdup_internal(), agstrfree(), and refstrbind().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strdict_free()

static void strdict_free ( strdict_t **  dict)
static

Definition at line 289 of file refstr.c.

References free(), NULL, and TOMBSTONE.

Referenced by agstrclose().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strdict_hash()

static size_t strdict_hash ( const char *  s,
bool  is_html 
)
static

derive hash for a given reference-counted string

Parameters
sThe reference-counted string’s s member
is_htmlIs this an HTML-like string?
Returns
A hash digest suitable for dictionary indexing

Definition at line 151 of file refstr.c.

References hash, and NULL.

Referenced by strdict_add(), strdict_find(), and strdict_remove().

Here is the caller graph for this function:

◆ strdict_new()

static strdict_t * strdict_new ( void  )
static

Definition at line 144 of file refstr.c.

References gv_alloc().

Referenced by refdict().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ strdict_remove()

static void strdict_remove ( strdict_t dict,
const refstr_t key 
)
static

Definition at line 256 of file refstr.c.

References strdict_t::buckets, strdict_t::capacity_exp, free(), refstr_t::is_html, NULL, refstr_eq(), refstr_t::s, strdict_t::size, strdict_hash(), and TOMBSTONE.

Referenced by agstrfree().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ Refdict_default

strdict_t* Refdict_default
static

Definition at line 60 of file refstr.c.

Referenced by refdict().

◆ TOMBSTONE

refstr_t* const TOMBSTONE = (refstr_t *)-1
static

a sentinel, marking a dictionary bucket from which an element has been deleted

Definition at line 158 of file refstr.c.

Referenced by strdict_add(), strdict_find(), strdict_free(), and strdict_remove().