Subversion Repositories PlanixRsrch.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
 * Copyright 2019, The PLANIX Project
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions are
6
 * met:
7
 *
8
 * 1. Redistributions of source code must retain the above copyright notice,
9
 * this list of conditions and the following disclaimer.
10
 *
11
 * 2. Redistributions in binary form must reproduce the above copyright
12
 * notice, this list of conditions and the following disclaimer in the
13
 * documentation and/or other materials provided with the distribution.
14
 *
15
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
19
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 */
27
 
28
 
29
#include "mavl.h"
30
 
31
/**
32
 * Create a simple AVL tree
33
 * @param cmp pointer to compare function
34
 * @param del pointer to delete function which is called when an element
35
 * will be deletet
36
 * @param dta_size size of a data element
37
 * @return pointer to a #mavl struct. If the return value is NULL something
38
 * went wrong, and you should consult errno to get details.
39
 */
40
struct mavl *
41
mavl_create(int (*cmp) (const void *, const void *),
42
			 void (*del) (void *), size_t data_size){
43
	struct mavl *t = malloc(sizeof(struct mavl));
44
	if (!t)
45
		return NULL;
46
	t->root = NULL;
47
	t->count = 0;
48
	t->cmp = cmp;
49
	t->del = del;
50
	t->data_size = data_size;
51
 
52
	t->malloc = malloc;
53
	t->free = free;
54
	return t;
55
}