/// //Subdivides an oct tree node into 8 child nodes, re-adding all occupants to the oct tree // //Parameters: // tree: A pointer to the oct tree in which this node lives // node: A pointer to the node being subdivided static void OctTree_Node_Subdivide(OctTree* tree, struct OctTree_Node* node) { //Allocate this nodes children node->children = OctTree_Node_AllocateChildren(); //Initialize this nodes children OctTree_Node_InitializeChildren(tree, node); unsigned int numOccupants = node->data->size; //Create a temporary list of occupants GObject** occupants = (GObject**)malloc(sizeof(GObject**) * numOccupants); //Copy occupants from node into temporary list memcpy(occupants, node->data->data, sizeof(GObject**) * numOccupants); //Clear the node's data DynamicArray_Clear(node->data); GObject* current; //re-add all contents to the node for(unsigned int i = 0; i < numOccupants; i++) { //Get the GObject* at index i current = occupants[i]; //Add the GObject* back into the node OctTree_Node_Add(tree, node, current); } //Free the temporary list of occupants free(occupants); }
/// //Subdivides an oct tree node into 8 child nodes, re-adding all occupants to the oct tree //Also removes the corresponding log entry for the parent node from the occupants, //And adds the necessary child node log entries // //Parameters: // tree: A pointer to the oct tree inw hcihc this node lives // node: A pointer to the node being subdivided static void OctTree_Node_SubdivideAndLog(OctTree*tree, struct OctTree_Node* node) { //Allocate this nodes children node->children = OctTree_Node_AllocateChildren(); //Initialize this nodes children OctTree_Node_InitializeChildren(tree, node); unsigned int numOccupants = node->data->size; //Create a temporary list of occupants GObject** occupants = (GObject**)malloc(sizeof(GObject**) * numOccupants); //Copy occupants from node into temporary list memcpy(occupants, node->data->data, sizeof(GObject**) * numOccupants); //Clear the node's data DynamicArray_Clear(node->data); //re-add all contents to the node GObject* current; for(unsigned int i = 0; i < numOccupants; i++) { //Get the GObject* at index i current = occupants[i]; //Get this log of this object DynamicArray* log = (DynamicArray*)HashMap_LookUp(tree->map, ¤t, sizeof(GObject*))->data; //Find parent node in the log for(unsigned int j = 0; j < log->size; j++) { if(((struct OctTree_NodeStatus*)DynamicArray_Index(log, j))->node == node) { //And remove it DynamicArray_RemoveAndReposition(log, j); break; } } //Add the GObject* back into the node OctTree_Node_AddAndLog(tree, node, current); } //Free the temporary list of occupants free(occupants); }
/// //Increases the internal storage of the hashmap, and re-hashes all existing key value pairs // //Parameters: // map: THe hashmap to increase the internal storage of static void HashMap_Grow(HashMap* map) { //Grow it DynamicArray_Grow(map->data); //Copy data struct HashMap_KeyValuePair** copy = (struct HashMap_KeyValuePair**)malloc(sizeof(struct HashMap_KeyValuePair*) * map->data->size); memcpy(copy, map->data->data, sizeof(struct HashMap_KeyValuePair*) * map->data->size); //Save size unsigned int size = map->data->size; //Clear dynamic array DynamicArray_Clear(map->data); //Re-Add all entries for(unsigned int i = 0; i < size; i++) { HashMap_AddPair(map, copy[i]); } }