BTree::BTree(short leafCapacity, short nodeCapacity, jobject pagedFile, jobject pagePoolProxy, jobject spaceManagerPolicy, JNIEnv *env, int klassIndexPageId) { root = NULL; this->pageIds = new PageIds(env, spaceManagerPolicy); this->pageIds->add(klassIndexPageId); this->leafCapacity = leafCapacity; this->nodeCapacity = nodeCapacity; this->pagedFile = env->NewGlobalRef(pagedFile); this->pagePoolProxy = env->NewGlobalRef(pagePoolProxy); this->spaceManagerPolicy = env->NewGlobalRef(spaceManagerPolicy); this->env = env; this->klassIndexPageId = klassIndexPageId; initIDs(); }
/* * Class: com_sun_glass_ui_lens_LensApplication * Method: _initIDs * Signature: ()V */ JNIEXPORT void JNICALL Java_com_sun_glass_ui_lens_LensApplication__1initIDs (JNIEnv *env, jclass _jApplicationClass) { jApplicationClass = _jApplicationClass; initIDs(env); }
//Reads the existing items from file and puts them into a double linked list, sorted by id void init(FILE *f) { FILE *file = f; char buffer[MAX_DESC_LEN]; if(!fgets(buffer,95,file)){ if(!feof){ quit("Error reading file"); } } else { firstItem = malloc(sizeof(ToDoItem)); sscanf(buffer,"%u %[^\n]", &firstItem->id, firstItem->desc); firstItem->prev = NULL; ToDoItem *last = firstItem; while(fgets(buffer,MAX_DESC_LEN,file)){ ToDoItem *current = malloc(sizeof(ToDoItem)); sscanf(buffer,"%d %[^\n]",¤t->id,current->desc); //biggest is the item the item that is just bigger than the current (next biggest) ToDoItem *biggest = firstItem; while(biggest->id <= current->id && biggest->next != NULL){ biggest = biggest->next; } //If current does not have a "biggest", as in there is no item with a bigger id than current if(current->id >= biggest->id){ //attach behind biggest current->prev = biggest; current->next = biggest->next; biggest->next = current; //if biggest was not last element, which really shouldn't be possible if(current->next != NULL){ current->next->prev = current; } } else { //attach in front of biggest current->next = biggest; current->prev = biggest->prev; biggest->prev = current; if(current->prev == NULL){ firstItem = current; } else { current->prev->next = current; } } } fclose(file); while(last->prev !=NULL){ last = last->prev; } firstItem = last; initIDs(); } }