File: sparse-array.h

package info (click to toggle)
pspp 0.7.9%2Bgit20120620-1.1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 71,980 kB
  • sloc: ansic: 384,310; sh: 22,024; cpp: 1,445; yacc: 1,251; perl: 903; lisp: 868; makefile: 358; xml: 182; java: 5
file content (61 lines) | stat: -rw-r--r-- 2,595 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* PSPP - a program for statistical analysis.
   Copyright (C) 2007, 2009 Free Software Foundation, Inc.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>. */

/* Sparse array data structure.

   Implements a dictionary that associates a "unsigned long int"
   key with fixed-size values (elements).

   The implementation allocates elements in groups of moderate
   size, so it achieves maximum space efficiency when elements
   are clustered into groups of consecutive keys.  For the same
   reason, elements should be kept relatively small, perhaps a
   few pointer elements in size.

   The implementation is slightly more efficient both in time and
   space when indexes are kept small.  Thus, for example, if the
   indexes in use start from some fixed base value, consider
   using the offset from that base as the index value. */

#ifndef LIBPSPP_SPARSE_ARRAY_H
#define LIBPSPP_SPARSE_ARRAY_H 1

#include <stddef.h>
#include <stdbool.h>

struct pool;

struct sparse_array *sparse_array_create (size_t elem_size);
struct sparse_array *sparse_array_create_pool (struct pool *,
                                               size_t elem_size);
void sparse_array_destroy (struct sparse_array *);

unsigned long int sparse_array_count (const struct sparse_array *);

void *sparse_array_insert (struct sparse_array *, unsigned long int key);
void *sparse_array_get (const struct sparse_array *, unsigned long int key);
bool sparse_array_remove (struct sparse_array *, unsigned long int key);

void *sparse_array_first (const struct sparse_array *,
                          unsigned long int *idxp);
void *sparse_array_next (const struct sparse_array *,
                         unsigned long int skip, unsigned long int *idxp);
void *sparse_array_last (const struct sparse_array *,
                          unsigned long int *idxp);
void *sparse_array_prev (const struct sparse_array *,
                         unsigned long int skip, unsigned long int *idxp);

#endif /* libpspp/sparse-array.h */