DecisionTreePtr DecisionTreeNew(ExampleSpecPtr spec) { DecisionTreePtr dt = MNewPtr(sizeof(DecisionTree)); dt->nodeType = dtnGrowing; dt->spec = spec; dt->growingData = 0; dt->myclass = 0; dt->children = 0; dt->classDistribution = MNewPtr(sizeof(float) * ExampleSpecGetNumClasses(spec)); DecisionTreeZeroClassDistribution(dt); return dt; }
HashTable *HashTableNew(int size) { HashTable* table = NULL; int i = 0; table = MNewPtr(sizeof(HashTable)); table->size = size; table->array = MNewPtr(sizeof(VoidListPtr) * size); for(i = 0; i < size; i++) { table->array[i] = VLNew(); DebugError(table->array[i] == NULL, "Failed allocate in HashTableNew"); } return table; }
static char *_AllocateString(char *first) { char *second = MNewPtr(sizeof(char) * (strlen(first) + 1)); strcpy(second, first); return second; }
AttributeTrackerPtr AttributeTrackerNew(int numAttributes) { AttributeTrackerPtr at = MNewPtr(sizeof(AttributeTracker)); int i; at->bits = BitFieldNew((numAttributes / 8) + 1); at->numAttributes = numAttributes; at->numActiveAttributes = numAttributes; for(i = 0 ; i < numAttributes ; i++) { BitFieldSetBit(at->bits, i, 1); } return at; }
bool ReplaceStringInList(char *theString,char **theList,UINT32 theElement) // place theString into theList at the given position, freeing // any string that was there // NOTE: theElement must be in range // if there is a problem leave the entry untouched, SetError, and return false { char *newElement; if((newElement=(char *)MNewPtr(strlen(theString)+1))) { strcpy(newElement,theString); MDisposePtr(theList[theElement]); theList[theElement]=newElement; return(true); } return(false); }
int DecisionTreeGetMostCommonClass(DecisionTreePtr dt) { long *counts = MNewPtr(sizeof(long) * ExampleSpecGetNumClasses(dt->spec)); int i; int mostCommon; for(i = 0 ; i < ExampleSpecGetNumClasses(dt->spec) ; i++) { counts[i] = 0; } _GetMostCommonClass(dt, counts); mostCommon = 0; for(i = 1 ; i < ExampleSpecGetNumClasses(dt->spec) ; i++) { if(counts[i] > counts[mostCommon]) { mostCommon = i; } } MFreePtr(counts); return mostCommon; }
bool AddStringToList(char *theString,char ***theList,UINT32 *numElements) // add theString to theList // at any point, theList can be deleted by calling FreeStringList // if there is a problem, do not add the element, SetError, and return false { char **newList; UINT32 newLength; newLength=sizeof(char *)*((*numElements)+2); if((newList=(char **)MResizePtr(*theList,newLength))) { (*theList)=newList; if(((*theList)[*numElements]=(char *)MNewPtr(strlen(theString)+1))) { strcpy((*theList)[(*numElements)++],theString); (*theList)[*numElements]=NULL; // keep the list terminated with a NULL return(true); } } return(false); }