added compareOctalCodes() and support for null octal code in printOctalCode()

This commit is contained in:
ZappoMan 2013-04-24 22:49:09 -07:00
parent 594ff6a759
commit 4b726b7fba
2 changed files with 41 additions and 2 deletions

View file

@ -10,6 +10,9 @@
#include <cstring>
#include "SharedUtil.h"
#include "OctalCode.h"
#include "shared_Log.h"
using shared_lib::printLog;
int numberOfThreeBitSectionsInCode(unsigned char * octalCode) {
if (*octalCode == 255) {
@ -20,8 +23,13 @@ int numberOfThreeBitSectionsInCode(unsigned char * octalCode) {
}
void printOctalCode(unsigned char * octalCode) {
for (int i = 0; i < bytesRequiredForCodeLength(*octalCode); i++) {
outputBits(octalCode[i]);
if (!octalCode) {
printLog("NULL\n");
} else {
for (int i = 0; i < bytesRequiredForCodeLength(*octalCode); i++) {
outputBits(octalCode[i],false);
}
printLog("\n");
}
}
@ -126,3 +134,25 @@ float * firstVertexForCode(unsigned char * octalCode) {
return firstVertex;
}
OctalTreeDepth compareOctalCodes(unsigned char* codeA, unsigned char* codeB) {
if (!codeA || !codeB) {
return ILLEGAL_CODE;
}
OctalTreeDepth result = SHALLOWER; // assume it's shallower
int codeLenthA = numberOfThreeBitSectionsInCode(codeA);
int codeLenthB = numberOfThreeBitSectionsInCode(codeB);
if (codeLenthA > codeLenthB) {
result = DEEPER;
} else if (codeLenthA == codeLenthB) {
int numberOfBytes = bytesRequiredForCodeLength(*codeA); // they are the same!!
if (0 == memcmp(codeA,codeB,numberOfBytes)) {
result = EXACT_MATCH;
} else {
result = EQUAL_DEPTH;
}
}
return result;
}

View file

@ -23,4 +23,13 @@ unsigned char * childOctalCode(unsigned char * parentOctalCode, char childNumber
float * firstVertexForCode(unsigned char * octalCode);
void copyFirstVertexForCode(unsigned char * octalCode, float* output);
typedef enum {
SHALLOWER,
EQUAL_DEPTH,
EXACT_MATCH,
DEEPER,
ILLEGAL_CODE
} OctalTreeDepth;
OctalTreeDepth compareOctalCodes(unsigned char* code1, unsigned char* code2);
#endif /* defined(__hifi__OctalCode__) */