1 /* PSPP - computes sample statistics.
2 Copyright (C) 2007 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 /* Sparse array data structure.
21 Implements a dictionary that associates a "unsigned long int"
22 key with fixed-size values (elements).
24 The implementation allocates elements in groups of moderate
25 size, so it achieves maximum space efficiency when elements
26 are clustered into groups of consecutive keys. For the same
27 reason, elements should be kept relatively small, perhaps a
28 few pointer elements in size.
30 The implementation is slightly more efficient both in time and
31 space when indexes are kept small. Thus, for example, if the
32 indexes in use start from some fixed base value, consider
33 using the offset from that base as the index value. */
35 #ifndef LIBPSPP_SPARSE_ARRAY_H
36 #define LIBPSPP_SPARSE_ARRAY_H 1
41 #include <libpspp/hash.h>
43 struct sparse_array *sparse_array_create (size_t elem_size);
44 struct sparse_array *sparse_array_create_pool (struct pool *,
46 void sparse_array_destroy (struct sparse_array *);
48 unsigned long int sparse_array_count (const struct sparse_array *);
50 void *sparse_array_insert (struct sparse_array *, unsigned long int key);
51 void *sparse_array_get (const struct sparse_array *, unsigned long int key);
52 bool sparse_array_remove (struct sparse_array *, unsigned long int key);
54 void *sparse_array_scan (const struct sparse_array *,
55 unsigned long int *skip,
56 unsigned long int *key);
58 #endif /* libpspp/sparse-array.h */