GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
AG_TBL(3) FreeBSD Library Functions Manual AG_TBL(3)

AG_Tblagar variable hash table structure

#include <agar/core/tbl.h>

The AG_Tbl structure describes a hash table consisting of AG_Variable(3) elements. It is defined as follows:

typedef struct ag_tbl_bucket {
	AG_Variable  *ents;
	Uint         nEnts;
} AG_TblBucket;

typedef struct ag_tbl {
	AG_TblBucket *buckets;
	Uint         nBuckets;
} AG_Tbl;

AG_Tbl *
(Uint nBuckets, Uint flags);


void
(AG_Tbl *tbl, Uint nBuckets, Uint flags);


void
(AG_Tbl *tbl);


AG_Variable *
(AG_Tbl *tbl, const char *key);


int
(AG_Tbl *tbl, const char *key, void **p);


int
(AG_Tbl *tbl, const char *key);


int
(AG_Tbl *tbl, const char *key, const AG_Variable *V);


int
(AG_Tbl *tbl, const char *key, void *p);


int
(AG_Tbl *tbl, const char *key);


(AG_Variable *V, int i, int j, AG_Tbl *tbl);

The () function allocates and initializes a new, empty AG_Tbl. AG_TblInit() initializes an existing table structure. The following flags options are accepted:

AG_TBL_DUPLICATES
Allow duplicate keys in the database. Insert calls for duplicate keys will if this option is not set.

() frees the resources allocated by a table (the table structure itself is not freed).

() searches the table for an entry of the given name and returns a pointer to it. On failure, it returns NULL.

() returns 1 if there is a table entry matching the giving key.

() inserts an entry in the table, using the specified key. The contents of the variable are duplicated. On failure, the function returns -1 and sets an error message.

() removes the specified table entry by name. If there is no match, it returns -1 and sets an error message.

The () macro iterates V over every entry of table tbl, using variables i and j as iterators. Example usage:

AG_Tbl *tbl;
AG_Variable *V;
int i, j;
AG_TBL_FOREACH(V, i,j, tbl) {
	printf("Item: %s\n", V->name);
}

The following access functions accept a hash argument. They are useful in cases where it is inefficient to reevaluate the hash function repeatedly (e.g., a lookup followed by an insert).


Uint
(AG_Tbl *tbl, const char *key);


AG_Variable *
(AG_Tbl *tbl, Uint hash, const char *key);


int
(AG_Tbl *tbl, Uint hash, const char *key);


int
(AG_Tbl *tbl, Uint hash, const char *key, const AG_Variable *V);


int
(AG_Tbl *tbl, Uint hash, const char *key);

() computes and returns the hash for the specified key.

(), AG_TblExistsHash(), AG_TblInsertHash() and AG_TblDeleteHash() are variants of AG_TblLookup(), AG_TblExists(), AG_TblInsert(), and AG_TblDelete() with an additional hash argument.

AG_Intro(3), AG_Variable(3)

The AG_Tbl interface first appeared in Agar 1.4.0.

December 21, 2022 Agar 1.7

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.