/* * Insert a free block to suitable class, * notes: 1. it's independent at first, that is to say, we have already destroy_relationship(cur_blk) * 2. it'll be the first free block in its class */ static void insert(char *cur_blk, size_t asize) { // FIRST find the class to insert in int class_index = 0; class_index = find_class(asize); // see if there has already been any free block in this class // if there is, we need to modify the relationship of the old first free block char *old_first = REAL_ADDR((char *)GET(heap_listp + class_index * HSIZE)); int to_change_old_fisrt = 0; if (old_first != (char *)base_addr) { to_change_old_fisrt = 1; } // here we modify cur_blk's info PUT(HDRP(cur_blk), PACK(asize, 0)); PUT(FTRP(cur_blk), PACK(asize, 0)); PUT(heap_listp + class_index * HSIZE, (unsigned int)((unsigned long)cur_blk - base_addr)); PUT(PRED(cur_blk), 0); PUT(SUCC(cur_blk), 0); // here we modify the relationship of the old first free block if (to_change_old_fisrt == 1) { PUT(PRED(old_first), (unsigned int)((unsigned long)cur_blk - base_addr)); PUT(SUCC(cur_blk), (unsigned int)((unsigned long)old_first - base_addr)); } }
static void printblock(void *bp) { size_t hsize, halloc, fsize, falloc; hsize = GET_SIZE(HDRP(bp)); halloc = GET_ALLOC(HDRP(bp)); fsize = GET_SIZE(FTRP(bp)); falloc = GET_ALLOC(FTRP(bp)); if (hsize == 0) { printf("%p: EOL\n", bp); return; } printf("%p: header: [%d:%c] footer: [%d:%c]\n", bp, hsize, (halloc ? 'a' : 'f'), fsize, (falloc ? 'a' : 'f')); if(!GET_ALLOC(HDRP(bp))){ printf("%p: Predicessor: [0x%x] Successor: [0x%x]\n", bp, GET(PRED(bp)), GET(SUCC(bp))); } if(bp == heap_listp){ printf("%p: Predicessor: [0x%x] Successor: [0x%x]\n", bp, GET(PRED(bp)), GET(SUCC(bp))); } }
/********************************************************** * add_to_free_list * Update the old top of list's pred to point to bp, * Update bp's succ to point to the old top of list * Updates the free_list pointer to point to bp **********************************************************/ void add_to_free_list(void *bp) { printf("in add_to_free - Free list: %p\n", free_list); printf("in add_to_free - bp: %p\n", bp); printf("in add_to_tree - allocated? %d\n", GET_ALLOC(HDRP(bp))); if (free_list == NULL) { PUT(SUCC(bp), NULL); PUT(PRED(bp), NULL); free_list = bp; return; } // char * // for (;;) { // if (SUCC(bp) == NULL) return NULL; // if (GET(SUCC(bp)) == NULL) return NULL; // bp = GET(SUCC(bp)); // } PUT(PRED(free_list), bp); PUT(SUCC(bp), free_list); PUT(PRED(bp), NULL); printf("add_to_free - addr of prev: %p\n", PREV_FR_BP(bp)); printf("add_to_free - addr of succ: %p\n", NEXT_FR_BP(bp)); free_list = bp; }
int (list_insert_after) ( SCL_list_t a_list, SCL_iterator_t a_iterator, const void* a_data ) { S_SCL_list_t* const list = a_list; S_node_t* ilink = (S_node_t*)a_iterator; S_node_t* node; if (ilink == list->tail) return list_push_back (a_list, a_data); node = SCL_ALLOCATOR (sizeof(S_node_t)); if (node == NULL) return SCL_NOMEM; node->data = a_data; PRED(node) = ilink; SUCC(node) = SUCC(ilink); PRED(SUCC(ilink)) = node; SUCC(ilink) = node; list->count += 1; return SCL_OK; }
/* * delete_node: Remove a free block pointer from a segregated list. If * necessary, adjust pointers in predecessor and successor blocks * or reset the list head. */ static void delete_node(void *ptr) { int list = 0; size_t size = GET_SIZE(HEAD(ptr)); /* Select segregated list */ while ((list < LISTS - 1) && (size > 1)) { size >>= 1; list++; } if (PRED(ptr) != NULL) { if (SUCC(ptr) != NULL) { SET_PTR(SUCC_PTR(PRED(ptr)), SUCC(ptr)); SET_PTR(PRED_PTR(SUCC(ptr)), PRED(ptr)); } else { SET_PTR(SUCC_PTR(PRED(ptr)), NULL); free_lists[list] = PRED(ptr); } } else { if (SUCC(ptr) != NULL) { SET_PTR(PRED_PTR(SUCC(ptr)), NULL); } else { free_lists[list] = NULL; } } return; }
int (list_insert) (SCL_list_t a_list, size_t a_index, const void* a_data) { S_SCL_list_t* const list = a_list; S_node_t* ilink = list->head; S_node_t* node; if (a_index == 0) return list_push_front (a_list, a_data); if (a_index == a_list->count) return list_push_back (a_list, a_data); if (a_index > a_list->count) return SCL_NOTFOUND; node = SCL_ALLOCATOR (sizeof(S_node_t)); if (node == NULL) return SCL_NOMEM; node->data = a_data; while (--a_index > 0) ilink = SUCC(ilink); PRED(node) = ilink; SUCC(node) = SUCC(ilink); PRED(SUCC(ilink)) = node; SUCC(ilink) = node; list->count += 1; return SCL_OK; }
/* * delete_node: Remove a free block pointer from a segregated list. If * necessary, adjust pointers in predecessor and successor blocks * or reset the list head. */ static void delete_node(void *ptr) { //int list = 0; size_t size = GET_SIZE(HDRP(ptr)); /* Select segregated list */ /* while ((list < LISTS - 1) && (size > 1)) { size >>= 1; list++; }*/ if (PRED(ptr) != NULL) { if (SUCC(ptr) != NULL) { SET_PTR(SUCC_PTR(PRED(ptr)), SUCC(ptr)); SET_PTR(PRED_PTR(SUCC(ptr)), PRED(ptr)); } else { SET_PTR(SUCC_PTR(PRED(ptr)), NULL); // free_lists[list] = PRED(ptr); } } else { //intptr_t header1 = header + SUCC(ptr); if (SUCC(ptr) != NULL) { SET_PTR(PRED_PTR(SUCC(ptr)), NULL); head = SUCC(ptr); } else { head = 0; // free_lists[list] = NULL; } } return; }
void (list_splice) (SCL_list_t a_list1, size_t a_index, SCL_list_t a_list2) { S_SCL_list_t* const list1 = a_list1; S_SCL_list_t* const list2 = a_list2; if (a_index == 0) { list_join (list2, list1); list1->head = list2->head; list1->tail = list2->tail; list1->count = list2->count; list2->head = NULL; list2->tail = NULL; list2->count = 0; return; } if (list1->count <= a_index) { list_join (list1, list2); return; } { S_node_t* node1; S_node_t* node2; S_node_t* next; node1 = list1->head; node2 = list2->head; if (node2 == NULL) return; while (--a_index > 0) node1 = SUCC(node1); next = SUCC(node1); SUCC(node1) = node2; PRED(node2) = node1; node1 = list2->tail; SUCC(node1) = next; if (next != NULL) PRED(next) = node1; list1->count += list2->count; list2->head = NULL; list2->tail = NULL; list2->count = 0; } return; }
/********************************************************** * remove_from_free_list * Update bp's pred's succ to be bp's succ * Update bp's succ's pred to be bp's pred * **********************************************************/ void remove_from_free_list(void *bp) { if (bp == NULL) return; if (PRED(bp) == NULL) return; if (SUCC(bp) == NULL) return; char * pred_addr = PREV_FR_BP(bp); char * succ_addr = NEXT_FR_BP(bp); if (pred_addr != NULL) { PUT(SUCC(pred_addr), succ_addr); } if (succ_addr != NULL) { PUT(PRED(succ_addr), pred_addr); } }
static void add_lst(void *ptr){ void *temp_bp = root_listp; root_listp = ptr; //change root to new free block printf("Cur root: %x, size: %d, alloc: %d \n", root_listp, GET_SIZE(HDRP(root_listp)), GET_ALLOC(HDRP(root_listp))); printf("current succ: %x, cur_pred: %x\n", SUCC(temp_bp), PRED(temp_bp)); printf("current succ: %x, cur_pred: %x\n", SUCC(root_listp), PRED(root_listp) ); if (GET(SUCC(ptr)) && GET(PRED(ptr))){ debug_me(); PUT(SUCC(ptr), temp_bp); //change current succ pointer to the recent free block debug_me(); PUT(PRED(temp_bp), ptr); //change recent free block pred to the current new root ptr } printf("Add successful yeh!\n"); }
int mm_init(void) { debug_me(); char *bp; /* Create the initial empty heap */ if ((heap_listp = mem_sbrk(4*SWORD)) == (void *)-1) return -1; PUT(heap_listp, 0); /* Alignment padding */ PUT(heap_listp + (1*SWORD), PACK(DWORD, 1)); /* Prologue header */ PUT(heap_listp + (2*SWORD), PACK(DWORD, 1)); /* Prologue footer */ PUT(heap_listp + (3*SWORD), PACK(0, 1)); /* Epilogue header */ heap_listp += (2*SWORD); /* Extend the empty heap with a free block of CHUNKSIZE bytes */ printf("Start init\n"); if ( (bp = extend_heap(CHUNKSIZE/SWORD)) == NULL) return -1; PUT(SUCC(bp), NULL); PUT(PRED(bp), NULL); root_listp = bp; mm_check(); printf("Done init()\n"); return 0; }
/* * Initialize: return -1 on error, 0 on success. */ int mm_init(void) { // We have a set of pointers at the beginning of heap. // Each pointer points to the first free block of its size class. // Each pointer points to NULL as default if ((heap_listp = mem_sbrk(CLASSES_NUM * HSIZE)) == (void *)-1) return -1; for (int i = 0; i < CLASSES_NUM; i++) { PUT(heap_listp + i * HSIZE, 0); } // Then we have a prologue block // to avoid troubles when coalesce if ((prologue_blk = mem_sbrk(EXTRA)) == (void *)-1) return -1; prologue_blk += 3 * HSIZE; PUT(HDRP(prologue_blk), PACK(EXTRA, 1)); PUT(SUCC(prologue_blk), 0); PUT(PRED(prologue_blk), 0); PUT(FTRP(prologue_blk), PACK(EXTRA, 1)); prologue_blk -= 2 * HSIZE; base_addr = (unsigned long)prologue_blk; return 0; }
Word MAFUPMON(Word p, Word M, Word A) { Word B,d,Ap,a,ap,r; Step1: /* A = 0 */ if (A == 0) { B = 0; goto Return; } Step2: /* Compute inverse of leading coefficient and multiply. */ a = PLDCF(A); ap = MAFINV(p,M,a); if (ap == NIL) B = NIL; else { d = PDEG(A); Ap = PRED(A); if (Ap != 0) { B = MAFUPEPROD(p,M,ap,Ap); B = COMP2(d,PMON(1,0),B); } else B = PMON(PMON(1,0),d); } Return: /* Prepare for return. */ return(B); }
Word QepcadCls::ACCCVBCR(Word k, Word c, Word B1, Word b, Word* B1h) { Word d, nnf, dV, IV, cp, i, I_i, d_i, c_i, L, Q, Qb, Qbs, F, Fp, a; Step1: /* Initialization **********************************************/ a = NIL; /* this is the pseudo-sample point we're building up *******/ F = NIL; /* Useless now, could be usefull later. ********************/ d = 0; /* dimension of cell c_i. **********************************/ nnf = 0; /* number of variables not fixed. **************************/ dV = CINV(RED(PDEGV(k+1,B1))); /* vector of degrees of first k ****** variables of B1. ******************/ IV = LELTI(c,INDX); /* vector of indices of cell c. ******/ Step2: /* Loop over each level from 1 to k ****************************/ c_i = GVPC; for(i = 1; i <= k; i++) { I_i = LELTI(IV,i); d_i = LELTI(dV,i); c_i = LELTI(LELTI(c_i,CHILD),I_i); Step3: /* c_i is a section over a 0-dimensional cell ******************/ if ((I_i % 2 == 0) && d == 0) { a = SUFFIX(a,LELTI(b,i)); continue; } Step4: /* c_i is a section over a cell of dimension greater than zero */ if ((I_i % 2 == 0) && d > 0) { for(L=SECTIONPOLS(i,c_i,GVPF),Qbs=1,Fp=NIL; L != NIL; L=RED(L)) { Q = RPFIP(i,LELTI(FIRST(L),PO_POLY)); Qb = SPECIALSUBSR(i,a,Q); /* Qb can't be zero, by definition of SECTIONPOLS */ Qbs = RPEMV(nnf + 1,Qb,LELTI(b,i)); if (Qbs == 0) { a = SUFFIX(a,LELTI(b,i)); break; } else Fp = COMP(Qb,Fp); } if (L == NIL) { F = CCONC(F,Fp); nnf++; a = SUFFIX(a,NIL); } } Step5: /* c_i is a sector *********************************************/ if (I_i % 2 == 1) { d++; nnf++; a = SUFFIX(a,NIL); } } /*Step6: a is the psuedo-sample point, check that B1 is univariate at a. */ bool uniq = true; Word B1b = SPECIALSUBSR(k+1,a,RPFIP(k+1,B1)); for(Word B1s = B1b; uniq && B1s != 0; B1s = PRED(B1s)) uniq = IPCONST(nnf,PLDCF(B1s)); if (B1h != 0) *B1h = B1b; return uniq ? TRUE : UNDET; }
static void remove_lst(void *ptr){ void *cur_pred = GET(PRED(ptr)); //get pointer of pred void *cur_suc = GET(SUCC(ptr)); // get pointer of suc if (cur_pred != NULL && cur_suc != NULL){ PUT(cur_pred, cur_suc); // swap to merge them together PUT(cur_suc + SWORD, cur_pred); } }
void MIONet_Ungetc (OOTint pmChar, void *pmFilePtr) { NetRecord *myNetRecord = (NetRecord *) pmFilePtr; myNetRecord -> tail = PRED (myNetRecord -> tail); myNetRecord -> buf [myNetRecord -> tail] = (char) pmChar; myNetRecord -> seenEOF = FALSE; } // MIONet_Ungetc
/* Remove block from the free list */ static void remove_block(void *bp){ // ef aðeins 1 block í listanum if(freeblockcount == 1){ PUT(SUCC(heap_listp), 0); } // blokk í enda listans else if(GET(SUCC(bp)) == 0){ //printf("FER Í RÉTTA LOOPU ÞEGAR FYRSTU BLOKK ER EITT !!!\n"); PUT(SUCC(GET(PRED(bp))), 0); } // blokk í miðjum lista else if(GET(PRED(bp)) != 0 && GET(SUCC(bp)) != 0){ PUT(GET(SUCC(bp)), (size_t)GET(PRED(bp))); PUT(SUCC(GET(PRED(bp))), (size_t)GET(SUCC(bp))); } freeblockcount--; }
static void insert_block(void *bp){ if(GET(SUCC(heap_listp)) == 0){ PUT(PRED(heap_listp), 0); PUT(SUCC(heap_listp), (size_t)bp); PUT(PRED(bp), (size_t)heap_listp); PUT(SUCC(bp), 0); } else{ PUT(PRED(bp), (size_t)heap_listp); PUT(SUCC(bp), (size_t)GET(SUCC(heap_listp))); // fæ segfault á línuna hér fyrir neðan !!! ??? PUT(PRED(GET(SUCC(heap_listp))), (size_t)bp); PUT(SUCC(heap_listp), (size_t)bp); } freeblockcount++; }
static void insert_node(void *bp, size_t size) { int listNum = 0; void *sptr = bp; void *iptr = NULL; //select list while ((listNum < LISTS - 1) && (size > 1)) { size >>= 1; listNum++; } sptr = *(seg_listp + listNum); while ((sptr != NULL) && (size > GET_SIZE(HDRP(sptr)))) { iptr = sptr; sptr = PRED(sptr); } if (sptr != NULL) { if (iptr != NULL) { STORE(PRED_PTR(bp), sptr); STORE(SUCC_PTR(sptr), bp); STORE(SUCC_PTR(bp), iptr); STORE(PRED_PTR(iptr), bp); } else { STORE(PRED_PTR(bp), sptr); STORE(SUCC_PTR(sptr), bp); STORE(SUCC_PTR(bp), NULL); } } else { if (iptr != NULL) { STORE(PRED_PTR(bp), NULL); STORE(SUCC_PTR(bp), iptr); STORE(PRED_PTR(iptr), bp); } else { STORE(PRED_PTR(bp), NULL); STORE(SUCC_PTR(bp), NULL); *(seg_listp + listNum) = bp; } } return; }
/* * mm_malloc - Allocate a block with at least size bytes of payload */ void *mm_malloc(size_t size) { size_t asize; /* Adjusted block size */ size_t extendsize; /* Amount to extend heap if no fit */ char *bp; int listNum = 0; /* Ignore spurious requests. */ if (size == 0) return (NULL); /* Adjust block size to include overhead and alignment reqs. */ if (size <= DSIZE) asize = 2 * DSIZE; else asize = DSIZE * ((size + (DSIZE) + (DSIZE - 1)) / DSIZE); while (listNum < LISTS) { if ((listNum == LISTS - 1) || (asize <= 1) && (*(seg_listp + listNum) != NULL)) { bp = *(seg_listp + listNum); while ((bp != NULL) && (asize > GET_SIZE(HDRP(bp)))) { bp = PRED(bp); } if (bp != NULL) break; } size >>= 1; listNum++; } if (bp == NULL) { extendsize = MAX(asize, CHUNKSIZE); if ((bp = extend_heap(extendsize)) == NULL) { return NULL; } } place(bp, asize); return bp; /* Search the free list for a fit. */ //if ((bp = find_fit(asize)) != NULL) { // place(bp, asize); // return (bp); //} /* No fit found. Get more memory and place the block. */ //extendsize = MAX(asize, CHUNKSIZE); //if ((bp = extend_heap(extendsize / WSIZE)) == NULL) // return (NULL); //place(bp, asize); //return bp; }
void* (list_remove_at) (SCL_list_t a_list, SCL_iterator_t a_iterator) { S_SCL_list_t* const list = a_list; S_node_t* node = (S_node_t*)a_iterator; const void* data; if (SUCC(node) != NULL) PRED(SUCC(node)) = PRED(node); if (PRED(node) != NULL) SUCC(PRED(node)) = SUCC(node); if (list->head == node) list->head = SUCC(node); if (list->tail == node) list->tail = PRED(node); data = node->data; list->count -= 1; SCL_DEALLOCATOR (node); return (void*)data; }
void (list_reverse) (SCL_list_t a_list) { S_SCL_list_t* const list = a_list; S_node_t* t; S_node_t* node; node = list->head; list->head = list->tail; list->tail = node; while (node != NULL) { t = SUCC(node); SUCC(node) = PRED(node); node = PRED(node) = t; } return; }
/* * mm_malloc - Allocate a new block by placing it in a free block, extending * heap if necessary. Blocks are padded with boundary tags and * lengths are changed to conform with alignment. */ void *mm_malloc(size_t size) { size_t asize; /* Adjusted block size */ size_t extendsize; /* Amount to extend heap if no fit */ void *ptr = NULL; /* Pointer */ int list = 0; /* List counter */ /* size_t checksize = size; // Copy of request size // (Reported to checking function) */ /* Filter invalid block size */ if (size == 0) return NULL; /* Adjust block size to include boundary tags and alignment requirements */ if (size <= DSIZE) { asize = 2 * DSIZE; } else { asize = DSIZE * ((size + (DSIZE) + (DSIZE - 1)) / DSIZE); } /* Select a free block of sufficient size from segregated list */ size = asize; while (list < LISTS) { if ((list == LISTS - 1) || ((size <= 1) && (free_lists[list] != NULL))) { ptr = free_lists[list]; // Ignore blocks that are too small or marked with the reallocation bit while ((ptr != NULL) && ((asize > GET_SIZE(HEAD(ptr))) || (GET_TAG(HEAD(ptr))))) { ptr = PRED(ptr); } if (ptr != NULL) break; } size >>= 1; list++; } /* Extend the heap if no free blocks of sufficient size are found */ if (ptr == NULL) { extendsize = MAX(asize, CHUNKSIZE); if ((ptr = extend_heap(extendsize)) == NULL) return NULL; } /* Place the block */ place(ptr, asize); /* // Check heap for consistency line_count++; if (CHECK && CHECK_MALLOC) { mm_check('a', ptr, checksize); } */ /* Return pointer to newly allocated block */ return ptr; }
void LKH::LKHAlg::NormalizeNodeList() { Node *t1, *t2; t1 = FirstNode; do { t2 = SUC(t1); t1->Pred = PRED(t1); t1->Suc = t2; } while ((t1 = t2) != FirstNode); }
static void delete_node(void *bp) { int listNum = 0; size_t size = GET_SIZE(HDRP(bp)); while ((listNum < LISTS - 1) && (size > 1)) { size >>= 1; listNum++; } if (PRED(bp) != NULL) { if (SUCC(bp) != NULL) { STORE(SUCC_PTR(PRED(bp)), SUCC(bp)); STORE(PRED_PTR(SUCC(bp)), PRED(bp)); } else { STORE(SUCC_PTR(PRED(bp)), NULL); *(seg_listp + listNum) = PRED(bp); } } else { if (SUCC(bp) != NULL) { STORE(PRED_PTR(SUCC(bp)), NULL); } else { *(seg_listp + listNum) = NULL; } } return; }
void* (list_remove) (SCL_list_t a_list, size_t a_index) { S_SCL_list_t* const list = a_list; S_node_t* node = list->head; const void* data; if (list->count <= a_index) return NULL; while (a_index-- > 0) node = SUCC(node); if (SUCC(node) != NULL) PRED(SUCC(node)) = PRED(node); if (PRED(node) != NULL) SUCC(PRED(node)) = SUCC(node); if (list->head == node) list->head = SUCC(node); if (list->tail == node) list->tail = PRED(node); data = node->data; list->count -= 1; SCL_DEALLOCATOR (node); return (void*)data; }
/* * mm_malloc - Allocate a block by incrementing the brk pointer. * Always allocate a block whose size is a multiple of the alignment. * * Role : * 1. The mm_malloc routine returns a pointer to an allocated block payload. * 2. The entire allocated block should lie within the heap region. * 3. The entire allocated block should overlap with any other chunk. * * Return value : Always return the payload pointers that are alligned to 8 bytes. */ void *mm_malloc(size_t size) { size_t asize; /* Adjusted block size */ size_t extendsize; /* Amount to extend heap if no fit */ void *ptr = NULL; /* Pointer */ // Ignore size 0 cases if (size == 0) return NULL; // Align block size if (size <= DSIZE) { asize = 2 * DSIZE; } else { asize = ALIGN(size+DSIZE); } int list = 0; size_t searchsize = asize; // Search for free block in segregated list while (list < LISTLIMIT) { if ((list == LISTLIMIT - 1) || ((searchsize <= 1) && (segregated_free_lists[list] != NULL))) { ptr = segregated_free_lists[list]; // Ignore blocks that are too small or marked with the reallocation bit while ((ptr != NULL) && ((asize > GET_SIZE(HDRP(ptr))) || (GET_TAG(HDRP(ptr))))) { ptr = PRED(ptr); } if (ptr != NULL) break; } searchsize >>= 1; list++; } // if free block is not found, extend the heap if (ptr == NULL) { extendsize = MAX(asize, CHUNKSIZE); if ((ptr = extend_heap(extendsize)) == NULL) return NULL; } // Place and divide block ptr = place(ptr, asize); // Return pointer to newly allocated block return ptr; }
/* * insert_node - Insert a block pointer into a segregated list. Lists are * segregated by byte size, with the n-th list spanning byte * sizes 2^n to 2^(n+1)-1. Each individual list is sorted by * pointer address in ascending order. */ static void insert_node(void *ptr, size_t size) { int list = 0; void *search_ptr = ptr; void *insert_ptr = NULL; /* Select segregated list */ while ((list < LISTS - 1) && (size > 1)) { size >>= 1; list++; } /* Select location on list to insert pointer while keeping list organized by byte size in ascending order. */ search_ptr = free_lists[list]; while ((search_ptr != NULL) && (size > GET_SIZE(HEAD(search_ptr)))) { insert_ptr = search_ptr; search_ptr = PRED(search_ptr); } /* Set predecessor and successor */ if (search_ptr != NULL) { if (insert_ptr != NULL) { SET_PTR(PRED_PTR(ptr), search_ptr); SET_PTR(SUCC_PTR(search_ptr), ptr); SET_PTR(SUCC_PTR(ptr), insert_ptr); SET_PTR(PRED_PTR(insert_ptr), ptr); } else { SET_PTR(PRED_PTR(ptr), search_ptr); SET_PTR(SUCC_PTR(search_ptr), ptr); SET_PTR(SUCC_PTR(ptr), NULL); /* Add block to appropriate list */ free_lists[list] = ptr; } } else { if (insert_ptr != NULL) { SET_PTR(PRED_PTR(ptr), NULL); SET_PTR(SUCC_PTR(ptr), insert_ptr); SET_PTR(PRED_PTR(insert_ptr), ptr); } else { SET_PTR(PRED_PTR(ptr), NULL); SET_PTR(SUCC_PTR(ptr), NULL); /* Add block to appropriate list */ free_lists[list] = ptr; } } return; }
static void place(void *ptr, size_t asize) { size_t csize = GET_SIZE(HDRP(ptr)); if ((csize - asize) >= (2*DWORD)) { debug_me(); PUT(HDRP(ptr), PACK(asize, 1)); PUT(FTRP(ptr), PACK(asize, 1)); void *old_pred = GET(PRED(ptr)); void *old_succ = GET(SUCC(ptr)); printf("old_pred: %x, old_succ: %x\n", old_pred, old_succ); /* pointer shift to the next alrdy */ ptr = NEXT_BLKP(ptr); PUT(HDRP(ptr), PACK(csize-asize, 0)); PUT(FTRP(ptr), PACK(csize-asize, 0)); root_listp = ptr; if (old_pred != NULL && old_succ != NULL){ debug_me(); PUT(PRED(ptr), old_pred); PUT(SUCC(ptr), old_succ); print_hdrp(ptr); print_snp(ptr); print_hdrp(old_pred); PUT(old_pred, ptr); PUT(old_succ + SWORD, ptr); debug_me(); } debug_me(); } else { debug_me(); PUT(HDRP(ptr), PACK(csize, 1)); PUT(FTRP(ptr), PACK(csize, 1)); remove_lst(ptr); } }
// Perform a exact search for the string w using the backwards algorithm void SBWT::backwardSearch(std::string w) const { std::cout << "Searching for " << w << "\n"; int len = w.size(); int j = len - 1; char curr = w[j]; int r_lower = PRED(curr); int r_upper = r_lower + OCC(curr, m_bwStr.length() - 1) - 1; --j; std::cout << "Starting point: " << r_lower << "," << r_upper << "\n"; for(;j >= 0; --j) { curr = w[j]; printf("RL = C(%c) + O(%c,%d) + %zu\n", curr, curr, r_lower - 1, m_numStrings); printf("RU = C(%c) + O(%c,%d)\n", curr, curr, r_upper); printf("RL = %zu + %zu + %zu\n", (size_t)PRED(curr), (size_t)OCC(curr, r_lower - 1), m_numStrings); printf("RU = %zu + %zu\n", (size_t)PRED(curr), (size_t)OCC(curr, r_upper)); r_lower = PRED(curr) + OCC(curr, r_lower - 1); r_upper = PRED(curr) + OCC(curr, r_upper) - 1; printf("Curr: %c, Interval now: %d,%d\n", curr, r_lower, r_upper); } std::cout << "Interval found: " << r_lower << "," << r_upper << "\n"; }