File: rarray.pod

package info (click to toggle)
roy 1.0.2-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,072 kB
  • ctags: 776
  • sloc: sh: 7,068; ansic: 6,292; makefile: 248
file content (58 lines) | stat: -rw-r--r-- 1,728 bytes parent folder | download
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
=head1 NAME

rchunk - Roy variable sized arrays

=head1 SYNOPSIS

#include <roy.h>

=head1 DESCRIPTION

Implements variable sized arrays.  These arrays are allocated in chunks, with
the each chunk pointing to the next.  This structure has the advantage that
many of the entries are in order in memory, which allows you to walk them
in order very fast, as this is usually the way that the cache is implemented.

If you are storing structures in the array, it also has the advantage that
the members of the structure exist in the linear array, again increasing
cache hits of the structure members.

They may also be used to implement stacks.

Thay are also used as a linked list replacement with less overhead (no
next/previous pointers).

=head1 RARRAY_FOREACH (array, entry)

Because the array is broken up into chunks (see rarray_new(3)), in order to
walk the array, you must use the RARRAY_FOREACH macro.

This macro walks through the array, assigning 'entry' to the
concequent array entry through each iteration.  The programmer can
use C<break>, C<continue>, or C<goto> safely.  All rarray functions
can be called safely inside the RLIST_FOREACH macro except
rarray_free(3).  You also cannot remove the next item in the array,
as a pointer is kept to it through each iteration.

=item EXAMPLE

To walk an array:

        MyEntry *entry;
        RArray *array;

        /* ... */

        RARRAY_FOREACH (array, entry) {
                /* do something with entry */
                entry->foo++;
        } RFOREACH_CLOSE;


=head1 SEE ALSO

rarray(3), rarray_append(3), rarray_free(3), 
rarray_last(3), rarray_len(3), rarray_new(3), 
rarray_nth(3), rarray_peak(3), rarray_pop(3), 
rarray_push(3), rarray_set_len(3), roy(3)