From ce9c392e2468bb7f796a6b563214433f8adfbb72 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 5 Feb 2013 15:13:14 -0800 Subject: [PATCH] routines for converting to/from variable length octal codes --- Source/octal.cpp | 24 ++++++++++++++++++++++-- Source/octal.h | 9 +++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Source/octal.cpp b/Source/octal.cpp index 2c648102dc..355ac3d292 100644 --- a/Source/octal.cpp +++ b/Source/octal.cpp @@ -8,12 +8,14 @@ // Various subroutines for converting between X,Y,Z coords and octree coordinates. // +#include "util.h" +#include "octal.h" + const int X = 0; const int Y = 1; const int Z = 2; -#include "util.h" -#include "octal.h" +domainNode rootNode; // Given a position vector between zero and one (but less than one), and a voxel scale 1/2^scale, // returns the smallest voxel at that scale which encloses the given point. @@ -24,3 +26,21 @@ void getVoxel(float * pos, int scale, float * vpos) { vpos[Z] = floor(pos[Z]*vscale)/vscale; } +domainNode* createNode(int lengthInBits, char * octalData, + char * hostname, char * nickname, int domain_id) { + domainNode * currentNode = &rootNode; + for (int i = 0; i < lengthInBits; i+=3) { + char octet = 0; + if (i%8 < 6) octet = octalData[i/8] << (i%8); + else { + octet = octalData[i/8] << (i%8) && ((octalData[i/8 + 1] >> (i%8)) << (8 - i%8)); + } + if (currentNode->child[octet] == NULL) currentNode->child[octet] = new domainNode; + currentNode = currentNode->child[octet]; + } + // Copy in the new node info... + strcpy(currentNode->hostname, hostname); + strcpy(currentNode->nickname, nickname); + currentNode->domain_id = domain_id; + return currentNode; +} diff --git a/Source/octal.h b/Source/octal.h index 672ad32362..06872e2658 100644 --- a/Source/octal.h +++ b/Source/octal.h @@ -11,4 +11,13 @@ #include +struct domainNode { + domainNode * child[8]; + char * hostname; + char * nickname; + int domain_id; +}; + + + #endif /* defined(__interface__octal__) */