+/* Recursive freeing of node function */
+void freeTree(void *base, unsigned index) {
+ void *current = base, *next;
+ if (base != NULL) {
+ /* Branch level */
+ if (index < 8) {
+ /* Free horizontaly */
+ do {
+ /* Free children */
+ if (((struct branch *)current)->child != NULL) {
+ freeTree(((struct branch *)current)->child, index + 1);
+ }
+ /* Free current and switch to next */
+ next = ((struct branch *)current)->next;
+ free(current);
+ current = next;
+ } while (current != NULL);
+ /* Leaf level */
+ } else {
+ /* Free horizontaly */
+ do {
+ /* Free current and switch to next */
+ next = ((struct leaf *)current)->next;
+ free(current);
+ current = next;
+ } while (current != NULL);
+ }
+ }
+}
+