Atrinik Server 2.5
Defines | Functions | Variables
server/shstr.c File Reference
#include <global.h>
#include "shstr.h"

Go to the source code of this file.

Functions

void init_hash_table ()
static unsigned long hashstr (const char *str)
static shared_stringnew_shared_string (const char *str)
shstradd_string (const char *str)
shstradd_refcount (shstr *str)
int query_refcount (shstr *str)
shstrfind_string (const char *str)
void free_string_shared (shstr *str)
void ss_dump_statistics (char *buf, size_t size)
void ss_dump_table (int what, char *buf, size_t size)

Variables

static shared_stringhash_table [TABLESIZE]

Detailed Description

This is a simple shared strings package with a simple interface.

Author:
Kjetil T. Homme, Oslo 1992.

Definition in file shstr.c.


Function Documentation

shstr* add_refcount ( shstr str)

This will increase the refcount of the string str.

Parameters:
strString which must have been returned from a previous add_string().
Returns:
str.

Definition at line 203 of file shstr.c.

shstr* add_string ( const char *  str)

This will add 'str' to the hash table. If there's no entry for this string, a copy will be allocated, and a pointer to that is returned.

Parameters:
strString to share.
Returns:
Pointer to string identical to str, but shared.

Definition at line 107 of file shstr.c.

shstr* find_string ( const char *  str)

Searches a string in the shared strings.

Parameters:
strString to search for.
Returns:
Pointer to identical string or NULL.

Definition at line 235 of file shstr.c.

void free_string_shared ( shstr str)

This will reduce the refcount, and if it has reached 0, str will be freed.

Parameters:
strString to release, which must have been returned from a previous add_string().

Definition at line 284 of file shstr.c.

static unsigned long hashstr ( const char *  str) [static]

Hashing function used by the shared string library.

Parameters:
strString to hash.
Returns:
Hash of string, suitable for use in hash_table.

Definition at line 50 of file shstr.c.

void init_hash_table ( )

Initializes the hash-table used by the shared string library.

Definition at line 41 of file shstr.c.

static shared_string* new_shared_string ( const char *  str) [static]

Allocates and initializes a new shared_string structure, containing the string str.

Parameters:
strString to store.
Returns:
Sharing structure.

Definition at line 78 of file shstr.c.

int query_refcount ( shstr str)

This will return the refcount of the string str.

Parameters:
strString which must have been returned from a previous add_string().
Returns:
Refcount of the string.

Definition at line 226 of file shstr.c.

void ss_dump_statistics ( char *  buf,
size_t  size 
)

A call to this function will cause the statistics to be dumped into specified buffer.

The routines will gather statistics if SS_STATISTICS is defined.

Parameters:
bufBuffer which will contain dumped information.
sizeBuffer's size.

Definition at line 343 of file shstr.c.

void ss_dump_table ( int  what,
char *  buf,
size_t  size 
)

Dump the contents of the shared string tables.

Parameters:
whatCombination of flags:
  • ::SS_DUMP_TABLE: Dump the contents of the hash table to log.
  • ::SS_DUMP_TOTALS: Return a string which says how many entries etc. there are in the table.
bufBuffer that will contain total information if (what & SS_DUMP_TABLE). Left untouched else.
sizeBuffer's size.

Definition at line 370 of file shstr.c.


Variable Documentation

shared_string* hash_table[TABLESIZE] [static]

Hash table to store our strings.

Definition at line 37 of file shstr.c.