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

atoms.h File Reference


Detailed Description

Atom management.

Author:
Raphael Manfredi
Date:
2002-2003

#include "common.h"

Go to the source code of this file.

Defines

#define GENERATE_ATOM_FREE_NULL(name, type)
 These functions dereference the given atom and nullify the pointer.
#define GENERATE_ATOM_CHANGE(name, type)
 These functions set an atom to a new value.

Enumerations

enum  atom_type {
  ATOM_STRING, ATOM_GUID, ATOM_SHA1, ATOM_TTH,
  ATOM_UINT64, ATOM_FILESIZE, NUM_ATOM_TYPES
}

Functions

gconstpointer atom_get (enum atom_type type, gconstpointer key)
 Get atom of given `type', whose value is `key'.
void atom_free (enum atom_type type, gconstpointer key)
 Remove one reference from atom.
const gchar * atom_str_get (const gchar *k)
void atom_str_free (const gchar *k)
const gchar * atom_guid_get (const gchar *k)
void atom_guid_free (const gchar *k)
const struct sha1atom_sha1_get (const struct sha1 *k)
void atom_sha1_free (const struct sha1 *k)
const struct tthatom_tth_get (const struct tth *k)
void atom_tth_free (const struct tth *k)
const guint64 * atom_uint64_get (const guint64 *k)
void atom_uint64_free (const guint64 *k)
const filesize_tatom_filesize_get (const filesize_t *k)
void atom_filesize_free (const filesize_t *k)
void atoms_init (void)
 Initialize atom structures.
void atoms_close (void)
 Shutdown atom structures, freeing all remaining atoms.
guint filesize_hash (gconstpointer key)
 Calculate the 32-bit hash of a filesize_t.
gint filesize_eq (gconstpointer a, gconstpointer b)
 Test two filesize_t for equality.
guint sha1_hash (gconstpointer key)
 Hash a SHA1 (20 bytes).
gint sha1_eq (gconstpointer a, gconstpointer b)
 Test two SHA1s for equality.
guint tth_hash (gconstpointer key)
 Hash a TTH (24 bytes).
gint tth_eq (gconstpointer a, gconstpointer b)
 Test two TTHs for equality.
guint guid_hash (gconstpointer key)
 Hash a GUID (16 bytes).
gint guid_eq (gconstpointer a, gconstpointer b)
 Test two GUIDs for equality.
guint uint64_hash (gconstpointer key)
 Calculate the 32-bit hash of a 64-bit integer.
gint uint64_eq (gconstpointer a, gconstpointer b)
 Test two 64-bit integers for equality.
guint binary_hash (const guchar *key, guint len)
 Hash `len' bytes starting from `key'.


Define Documentation

#define GENERATE_ATOM_CHANGE name,
type   ) 
 

Value:

static inline void \
atom_ ## name ## _change(const type *atom_ptr, const type value) \
{ \
    const void *atom = value ? atom_ ## name ## _get(value) : NULL; \
    atom_ ## name ## _free_null(atom_ptr); \
    *atom_ptr = atom; \
}
These functions set an atom to a new value.

The old atom is dereferenced. This prevents one issue: "value" might actually be the current atom. If it has a reference count of 1, dereferencing would free "value" as well and we end up with a corrupt atom.

#define GENERATE_ATOM_FREE_NULL name,
type   ) 
 

Value:

static inline void \
atom_ ## name ## _free_null(const type *k_ptr) \
{ \
    if (*k_ptr) { \
        atom_ ## name ## _free(*k_ptr); \
        *k_ptr = NULL; \
    } \
}
These functions dereference the given atom and nullify the pointer.

The atom may also point to NULL, so the caller does not have to check this.


Enumeration Type Documentation

enum atom_type
 

Enumeration values:
ATOM_STRING  Strings.
ATOM_GUID  GUIDs (binary, 16 bytes).
ATOM_SHA1  SHA1 (binary, 20 bytes).
ATOM_TTH  TTH (binary, 24 bytes).
ATOM_UINT64  integers (binary, 8 bytes)
ATOM_FILESIZE  filesize_t (binary)
NUM_ATOM_TYPES 


Function Documentation

void atom_filesize_free const filesize_t k  )  [inline, static]
 

const filesize_t* atom_filesize_get const filesize_t k  )  [inline, static]
 

void atom_free enum atom_type  type,
gconstpointer  key
 

Remove one reference from atom.

Dispose of atom if nobody references it anymore.

gconstpointer atom_get enum atom_type  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.

void atom_guid_free const gchar *  k  )  [inline, static]
 

const gchar* atom_guid_get const gchar *  k  )  [inline, static]
 

void atom_sha1_free const struct sha1 k  )  [inline, static]
 

const struct sha1* atom_sha1_get const struct sha1 k  )  [inline, static]
 

void atom_str_free const gchar *  k  )  [inline, static]
 

const gchar* atom_str_get const gchar *  k  )  [inline, static]
 

void atom_tth_free const struct tth k  )  [inline, static]
 

const struct tth* atom_tth_get const struct tth k  )  [inline, static]
 

void atom_uint64_free const guint64 *  k  )  [inline, static]
 

const guint64* atom_uint64_get const guint64 *  k  )  [inline, static]
 

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 starting from `key'.

gint filesize_eq gconstpointer  a,
gconstpointer  b
 

Test two filesize_t for equality.

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

guint filesize_hash gconstpointer  p  ) 
 

Calculate the 32-bit hash of a filesize_t.

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

gint guid_eq gconstpointer  a,
gconstpointer  b
 

Test two GUIDs for equality.

guint guid_hash gconstpointer  key  ) 
 

Hash a GUID (16 bytes).

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 tth_eq gconstpointer  a,
gconstpointer  b
 

Test two TTHs for equality.

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

guint tth_hash gconstpointer  key  ) 
 

Hash a TTH (24 bytes).

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  p  ) 
 

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

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


Generated on Sat Jun 30 17:53:25 2007 for gtk-gnutella by  doxygen 1.3.9.1