Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

atoms.c File Reference


Detailed Description

Atom management.

An atom is a single piece of information that is likely to be shared and which is therefore only allocated once: all other instances point to the common object.

Author:
Raphael Manfredi
Date:
2002-2003

#include <string.h>
#include "common.h"
#include "atoms.h"
#include "misc.h"
#include "glib-missing.h"
#include "walloc.h"
#include "override.h"

Data Structures

union  mem_chunk
struct  atom
 Atoms are ref-counted. More...

struct  table_desc
 Description of atom types. More...


Defines

#define ATOMS_SOURCE
#define ARENA_OFFSET   G_STRUCT_OFFSET(struct atom, arena)
#define atom_protect(a)
#define atom_unprotect(a)
#define atom_alloc(size)   g_malloc(size)
#define atom_dealloc(a)   g_free(a)

Typedefs

typedef atom atom_t
 Atoms are ref-counted.

typedef gint(* len_func_t )(gconstpointer v)
typedef const gchar *(* str_func_t )(gconstpointer v)
typedef table_desc table_desc_t
 Description of atom types.


Functions

 RCSID ("$Id:atoms.c, v 1.21 2005/12/27 16:29:29 cbiere Exp $")
gint str_len (gconstpointer v)
const gchar * str_str (gconstpointer v)
gint guid_len (gconstpointer v)
const gchar * guid_str (gconstpointer v)
gint sha1_len (gconstpointer v)
const gchar * sha1_str (gconstpointer v)
gint uint64_len (gconstpointer v)
const gchar * uint64_str (gconstpointer v)
guint binary_hash (const guchar *key, guint len)
 Hash `len' bytes (multiple of 4) starting from `key'.

guint guid_hash (gconstpointer key)
 Hash a GUID (16 bytes).

gint guid_eq (gconstpointer a, gconstpointer b)
 Test two GUIDs for equality.

guint sha1_hash (gconstpointer key)
 Hash a SHA1 (20 bytes).

gint sha1_eq (gconstpointer a, gconstpointer b)
 Test two SHA1s for equality.

gint uint64_eq (gconstpointer a, gconstpointer b)
 Test two 64-bit integers for equality.

guint uint64_hash (gconstpointer p)
 Calculate the 32-bit hash of a 64-bit integer.

void atoms_init (void)
 Initialize atom structures.

gpointer atom_get (gint type, gconstpointer key)
 Get atom of given `type', whose value is `key'.

void atom_free (gint type, gconstpointer key)
 Remove one reference from atom.

gboolean atom_warn_free (gpointer key, gpointer unused_value, gpointer udata)
 Warning about existing atom that should have been freed.

void atoms_close (void)
 Shutdown atom structures, freeing all remaining atoms.


Variables

table_desc_t atoms []
 The set of all atom types we know about.


Define Documentation

#define ARENA_OFFSET   G_STRUCT_OFFSET(struct atom, arena)
 

#define atom_alloc size   )     g_malloc(size)
 

#define atom_dealloc  )     g_free(a)
 

#define atom_protect  ) 
 

#define atom_unprotect  ) 
 

#define ATOMS_SOURCE
 


Typedef Documentation

typedef struct atom atom_t
 

Atoms are ref-counted.

The reference count is held at the beginning of the data arena. What we return to the outside is a pointer to arena[], not to the atom structure.

typedef gint(* len_func_t)(gconstpointer v)
 

typedef const gchar*(* str_func_t)(gconstpointer v)
 

typedef struct table_desc table_desc_t
 

Description of atom types.


Function Documentation

void atom_free gint  type,
gconstpointer  key
 

Remove one reference from atom.

Dispose of atom if nobody references it anymore.

gpointer atom_get gint  type,
gconstpointer  key
 

Get atom of given `type', whose value is `key'.

If the atom does not exist yet, `key' is cloned and makes up the new atom.

Returns:
the atom's value.

gboolean atom_warn_free gpointer  key,
gpointer  unused_value,
gpointer  udata
[static]
 

Warning about existing atom that should have been freed.

void atoms_close void   ) 
 

Shutdown atom structures, freeing all remaining atoms.

void atoms_init void   ) 
 

Initialize atom structures.

guint binary_hash const guchar *  key,
guint  len
 

Hash `len' bytes (multiple of 4) starting from `key'.

gint guid_eq gconstpointer  a,
gconstpointer  b
 

Test two GUIDs for equality.

guint guid_hash gconstpointer  key  ) 
 

Hash a GUID (16 bytes).

gint guid_len gconstpointer  unused_guid  )  [static]
 

Returns:
length of GUID.

const gchar * guid_str gconstpointer  v  )  [static]
 

Returns:
printable form of a GUID, as pointer to static data.

RCSID "$Id:atoms.  c,
v 1.21 2005/12/27 16:29:29 cbiere Exp $" 
 

gint sha1_eq gconstpointer  a,
gconstpointer  b
 

Test two SHA1s for equality.

Attention:
NB: This routine is visible for the download mesh.

guint sha1_hash gconstpointer  key  ) 
 

Hash a SHA1 (20 bytes).

Attention:
NB: This routine is visible for the download mesh.

gint sha1_len gconstpointer  unused_sha1  )  [static]
 

Returns:
length of SHA1.

const gchar * sha1_str gconstpointer  sha1  )  [static]
 

Returns:
printable form of a SHA1, as pointer to static data.

gint str_len gconstpointer  v  )  [static]
 

Returns:
length of string + trailing NUL.

const gchar * str_str gconstpointer  v  )  [static]
 

Returns:
printable form of a string, i.e. self.

gint uint64_eq gconstpointer  a,
gconstpointer  b
 

Test two 64-bit integers for equality.

Returns:
whether both referenced 64-bit integers are equal.

guint uint64_hash gconstpointer  key  ) 
 

Calculate the 32-bit hash of a 64-bit integer.

Returns:
the 32-bit hash value for the referenced 64-bit integer.

int uint64_len gconstpointer  unused_v  )  [static]
 

Returns:
length of an int.

const gchar * uint64_str gconstpointer  v  )  [static]
 

Returns:
printable form of an int, as pointer to static data.


Variable Documentation

table_desc_t atoms[] [static]
 

Initial value:

 {
    { "String", NULL, g_str_hash,  g_str_equal, str_len,    str_str  }, 
    { "GUID",   NULL, guid_hash,   guid_eq,     guid_len,   guid_str }, 
    { "SHA1",   NULL, sha1_hash,   sha1_eq,     sha1_len,   sha1_str }, 
    { "uint64", NULL, uint64_hash, uint64_eq,   uint64_len, uint64_str},
}
The set of all atom types we know about.


Generated on Sun Feb 12 10:49:59 2006 for Gtk-Gnutella by doxygen 1.3.6