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

« back to all changes in this revision

Viewing changes to src/namesize.c

  • 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: namesize.c,v 1.9 2004/01/14 20:52:33 rmanfredi Exp $
 
3
 *
 
4
 * Copyright (c) 2002-2003, Raphael Manfredi
 
5
 *
 
6
 * Handling of the (name, size) tuples.
 
7
 *
 
8
 *----------------------------------------------------------------------
 
9
 * This file is part of gtk-gnutella.
 
10
 *
 
11
 *  gtk-gnutella is free software; you can redistribute it and/or modify
 
12
 *  it under the terms of the GNU General Public License as published by
 
13
 *  the Free Software Foundation; either version 2 of the License, or
 
14
 *  (at your option) any later version.
 
15
 *
 
16
 *  gtk-gnutella is distributed in the hope that it will be useful,
 
17
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
 *  GNU General Public License for more details.
 
20
 *
 
21
 *  You should have received a copy of the GNU General Public License
 
22
 *  along with gtk-gnutella; if not, write to the Free Software
 
23
 *  Foundation, Inc.:
 
24
 *      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
25
 *----------------------------------------------------------------------
 
26
 */
 
27
 
 
28
#include "common.h"                     /* For safe compilation under USE_DMALLOC */
 
29
#include "namesize.h"
 
30
#include "override.h"                   /* Must be the last header included */
 
31
 
 
32
RCSID("$Id: namesize.c,v 1.9 2004/01/14 20:52:33 rmanfredi Exp $");
 
33
 
 
34
/*
 
35
 * namesize_hash
 
36
 *
 
37
 * Hash a `namesize_t' key.
 
38
 */
 
39
guint namesize_hash(gconstpointer key)
 
40
{
 
41
        const namesize_t *k = (const namesize_t *) key;
 
42
        guint32 hash;
 
43
 
 
44
        hash = g_str_hash(k->name);
 
45
        hash ^= k->size;
 
46
 
 
47
        return hash;
 
48
}
 
49
 
 
50
/*
 
51
 * namesize_eq
 
52
 *
 
53
 * Compare two `namesize_t' keys.
 
54
 */
 
55
gint namesize_eq(gconstpointer a, gconstpointer b)
 
56
{
 
57
        const namesize_t *ka = a;
 
58
        const namesize_t *kb = b;
 
59
 
 
60
        return ka->size == kb->size && 0 == strcmp(ka->name, kb->name);
 
61
}
 
62
 
 
63
/*
 
64
 * namesize_make
 
65
 *
 
66
 * Create a new namesize structure.
 
67
 */
 
68
namesize_t *namesize_make(const gchar *name, guint32 size)
 
69
{
 
70
        namesize_t *ns;
 
71
 
 
72
        ns = walloc(sizeof(*ns));
 
73
        ns->name = atom_str_get(name);
 
74
        ns->size = size;
 
75
 
 
76
        return ns;
 
77
}
 
78
 
 
79
/*
 
80
 * namesize_free
 
81
 *
 
82
 * Free a namesize structure.
 
83
 */
 
84
void namesize_free(namesize_t *ns)
 
85
{
 
86
        atom_str_free(ns->name);
 
87
        wfree(ns, sizeof(*ns));
 
88
}
 
89