aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/sset.c
blob: e9681e00ddd4636f261894546689c7746803f148 (plain)
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
// SPDX-License-Identifier: MIT
//
// sset.c - an all O(1) implementation of sparse sets as presented in:
//	"An Efficient Representation for Sparse Sets"
//	by Preston Briggs and Linda Torczon
//
// Copyright (C) 2017 - Luc Van Oostenryck

#include "sset.h"
#include "lib.h"
#include <stdlib.h>


struct sset *sset_init(unsigned int first, unsigned int last)
{
	unsigned int size = last - first + 1;
	struct sset *s = malloc(sizeof(*s) + size * 2 * sizeof(s->sets[0]));

	s->size = size;
	s->off = first;
	s->nbr = 0;
	return s;
}

void sset_free(struct sset *s)
{
	free(s);
}