~ubuntu-branches/ubuntu/karmic/gtk-gnutella/karmic

« back to all changes in this revision

Viewing changes to src/idtable.h

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Kleineidam
  • Date: 2004-05-22 15:26:55 UTC
  • Revision ID: james.westby@ubuntu.com-20040522152655-lyi6iaswmy4hq4wy
Tags: upstream-0.93.3.0
ImportĀ upstreamĀ versionĀ 0.93.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: idtable.h,v 1.5 2003/07/31 01:32:34 cbiere Exp $
 
3
 *
 
4
 * Copyright (c) 2001-2003, Richard Eckart
 
5
 *
 
6
 *----------------------------------------------------------------------
 
7
 * This file is part of gtk-gnutella.
 
8
 *
 
9
 *  gtk-gnutella is free software; you can redistribute it and/or modify
 
10
 *  it under the terms of the GNU General Public License as published by
 
11
 *  the Free Software Foundation; either version 2 of the License, or
 
12
 *  (at your option) any later version.
 
13
 *
 
14
 *  gtk-gnutella is distributed in the hope that it will be useful,
 
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 *  GNU General Public License for more details.
 
18
 *
 
19
 *  You should have received a copy of the GNU General Public License
 
20
 *  along with gtk-gnutella; if not, write to the Free Software
 
21
 *  Foundation, Inc.:
 
22
 *      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
23
 *----------------------------------------------------------------------
 
24
 */
 
25
 
 
26
#ifndef _idtable_h_
 
27
#define _idtable_h_
 
28
 
 
29
/*
 
30
 * The idtable provides a automatically growing table which can resolve
 
31
 * ids to values very fast. The ids are issues by the table and internally
 
32
 * refer to an array row in the table. The table starts with an initial size
 
33
 * and if full is extended by a definable number of rows. Initial size and
 
34
 * extend size are internally rounded up to a multiple of 32. There is no
 
35
 * limitation to the value and is can be queried whether a given id is in
 
36
 * use. 
 
37
 * You can also request special id/value combinations, but you need to keep
 
38
 * in mind that the ids are row numbers. The table is then automatically
 
39
 * grown to contain the requested id, but you can't shrink it later, because
 
40
 * that would mean that the row numbers change and the ids already issued
 
41
 * would become invalid.
 
42
 * If the application needs to shrink a table, I suggest creating a new
 
43
 * table and request the needed number of ids from that. Of course all
 
44
 * ids currently in use by the application must be updated. Once that is
 
45
 * done, flush and destroy the old table.
 
46
 */
 
47
 
 
48
#include <glib.h>
 
49
 
 
50
#define idtable_ids(tbl) (tbl->ids)
 
51
#define idtable_size(tbl) (tbl->size)
 
52
 
 
53
typedef struct idtable {
 
54
    guint32   size;      /* numbers of slots available */
 
55
    guint32   esize;     /* number of slots to add if table is full */
 
56
    guint32   ids;       /* numbers of slots currently used */
 
57
    guint32   last_id;   /* last issued id */
 
58
    guint32  *used_ids;  /* binary array of used ids */
 
59
    gpointer *data;      /* actual table array */
 
60
} idtable_t;
 
61
 
 
62
idtable_t *idtable_new(guint32 isize, guint32 esize);
 
63
 
 
64
void idtable_destroy(idtable_t *table);
 
65
 
 
66
guint32 idtable_new_id(idtable_t *tbl, gpointer value);
 
67
void idtable_new_id_value(idtable_t *tbl, guint32 id, gpointer value);
 
68
 
 
69
void idtable_free_id(idtable_t *tbl, guint32 id);
 
70
 
 
71
G_INLINE_FUNC gboolean idtable_is_id_used(idtable_t *tbl, guint32 id);
 
72
 
 
73
void idtable_set_value(idtable_t *tbl, guint32 id, gpointer value);
 
74
gpointer idtable_get_value(idtable_t *tbl, guint32 id);
 
75
 
 
76
#endif /* _idtable_h_ */