CObject
CCBinaryTree.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Brendan Bruner
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * bbruner@ualberta.ca
17  * July 13, 2016
18  */
23 #ifndef UTIL_CCBINARYTREE_H_
24 #define UTIL_CCBINARYTREE_H_
25 
26 #include <CITree.h>
27 #include <CCArrayList.h>
28 
29 /************************************************************************/
30 /* Class and vtable decalre. */
31 /************************************************************************/
86 {
87  /* Super class must always be first member */
88  /* of a C class struct. */
89  struct CObject cobject;
90 
91  /* Implementing the CITree interface. */
92  struct CITree citree;
93 
94  /* Private data. */
95  struct CCArrayList tree_backend;
96  unsigned char* swap_space_1;
97  unsigned char* key_space_1;
98  unsigned char* key_space_2;
99  signed char (*compare)(const void*, const void*);
100  size_t index;
101  size_t element_size;
102  size_t key_size;
103  size_t max_size;
104 };
105 
112 {
113  /* Space for a copy of the super class' virtual table must */
114  /* be the first member of a class virtual table declaration. */
115  struct CObject_VTable cobject_override;
116 
117  /* Since we are overriding the destructor, we need to keep */
118  /* keep a reference to the super class' implementation of */
119  /* the destructor. */
120  const struct CObject_VTable* cobject;
121 
122  /* Space for a copy of the implemented interface's virtual table */
123  struct CITree_VTable citree_override;
124 };
125 
133 
134 
135 /************************************************************************/
136 /* Constructor */
137 /************************************************************************/
175 CError CCBinaryTree
176 (
177  struct CCBinaryTree* self,
178  size_t element_size,
179  size_t max_size,
180  signed char (*compare)( const void*, const void* ),
181  size_t key_size
182 );
183 
184 
185 #endif /* UTIL_CCBINARYTREE_H_ */
CITree virtual table.
Definition: CITree.h:78
Base class.
Definition: Class.h:283
CCBinaryTree&#39;s vtable declaration.
Definition: CCBinaryTree.h:111
Implements the CITree interface with a binary tree/heap.
Definition: CCBinaryTree.h:85
CObject&#39;s virtual table declaration.
Definition: Class.h:306
Array implementation of CIList.
Definition: CCArrayList.h:92
const struct CCBinaryTree_VTable * CCBinaryTree_GetVTable()
Definition: CCBinaryTree.c:448
CError CCBinaryTree(struct CCBinaryTree *self, size_t element_size, size_t max_size, signed char(*compare)(const void *, const void *), size_t key_size)
Definition: CCBinaryTree.c:484
Tree data structure interface.
Definition: CITree.h:66