-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintervaltree.h
80 lines (68 loc) · 2.03 KB
/
intervaltree.h
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* CS 537 Programming Assignment 4 (Fall 2020)
* @author Julien de Castelnau
* @date 11/22/2020
* @brief Implementation of a simple balancing interval tree with search, insert, and print operations supported.
* @file intervaltree.h
*/
#include <stdbool.h>
#include <stdio.h>
#ifndef _INTTREE_
#define _INTTREE_
typedef struct interval_node_t {
size_t low; // low of current interval
size_t high; // high of current interval
size_t max; // max value present throughout entire subtree given by node
long fpos_start;
struct interval_node_t* left; // pointer to left interval node
struct interval_node_t* right; // pointer to right interval node
} IntervalNode;
bool it_contains(size_t low, size_t high, size_t x);
/**
* Constructs a new interval node
* @return a pointer to the IntervalNode
*/
IntervalNode* it_initnode(size_t low, size_t high);
/**
* Inserts an interval node into the tree.
*
* @param root Root of tree to insert into
* @param new New node to insert
*
* @return none
*/
void it_insert(IntervalNode* root, IntervalNode* new_node);
/**
* Finds an integer X within the entire tree.
*
* @param root Root of tree to search in
* @param x value to search for
*
* @return true if found, false if not.
*/
bool it_find_bool(IntervalNode* root, size_t x);
/**
* Finds an integer X within the entire tree.
*
* @param root Root of tree to search in
* @param x value to search for
*
* @return pointer to found node, NULL if not found.
*/
IntervalNode* it_find(IntervalNode* root, size_t x);
/**
* Walks a specified tree and prints all of its intervals.
*
* @param root Root of tree to print
*
* @return none
*/
void it_print(IntervalNode* root);
/**
* A "smart increment" function. Returns the value that proceeds the integer passed as an argument,
* assuming it is not greater than or equal to the whole tree, in which case the result is just 0.
*/
size_t it_giveNext(IntervalNode* root, size_t current);
void it_setFpos(IntervalNode* n, long p);
long it_getFpos(IntervalNode* n);
#endif