Browse Source Download (without any required ccan dependencies)

Module:

objset

Summary:

unordered set of pointers.

Dependencies:

Description:

This code implements a very simple unordered set of pointers. It's very fast to add and check if something is in the set; it's implemented by a hash table.

Example:

// Silly example to determine if an arg starts with a -
#include <ccan/objset/objset.h>
#include <stdio.h>

struct objset_arg {
        OBJSET_MEMBERS(const char *);
};

int main(int argc, char *argv[])
{
        struct objset_arg args;
        unsigned int i;

        objset_init(&args);
        // Put all args starting with - in the set.
        for (i = 1; i < argc; i++)
                if (argv[i][0] == '-')
                        objset_add(&args, argv[i]);

        if (objset_empty(&args))
                printf("No arguments start with -.\n");
        else {
                for (i = 1; i < argc; i++)
                        if (objset_get(&args, argv[i]))
                                printf("%i,", i);
                printf("\n");
        }
        return 0;
}
// Given 'a b c' outputs No arguments start with -.
// Given 'a -b c' outputs 2,
// Given 'a -b -c d' outputs 2,3,

License:

LGPL (v2.1 or any later version)