/* * lca_lookup * * Perform the constant time LCA computation, finding the least * common ancestor of x and y. * * Parameters: lca - an LCA_STRUCT structure * x - a suffix tree node * y - another suffix tree node * * Returns: the suffix tree node which is the LCA of x and y */ STREE_NODE lca_lookup(LCA_STRUCT *lca, STREE_NODE x, STREE_NODE y) { assert(lca && lca->tree && lca->type == LCA_LINEAR && x && y); SUFFIX_TREE tree = lca->tree; unsigned int *I = lca->I; unsigned int *A = lca->A; STREE_NODE *L = lca->L; // Shift idents so that they go from 1..num_nodes. unsigned int xid = (unsigned int)stree_get_ident(tree, x) + 1; unsigned int yid = (unsigned int)stree_get_ident(tree, y) + 1; /* * Steps 1 and 2. * * Step 1 here differs from the book in that it returns the most * significant bit counting from the right (and starting the count * with 0), and then simply OR's the k+1..32 bits of I[xid] and the * number 2^k. */ //printf("xid=%3d, I[xid]=%3d\n", xid, I[xid]); // printf("yid=%3d, I[yid]=%3d\n", yid, I[yid]); unsigned int k = MSB(I[xid] ^ I[yid]); unsigned int b = (I[xid] & HIGH_BITS(k+1)) | (1 << k); unsigned int j = h( (A[xid] & A[yid]) & HIGH_BITS(h(b)) ); // printf("k=%d, b=%d, j =%d\n", k, b, j); IF_STATS(lca->num_compares++); // Step 3. unsigned int l = h(A[xid]); STREE_NODE xbar, ybar; if (l == j) { xbar = x; } else { k = MSB(A[xid] & ~HIGH_BITS(j)); xbar = stree_get_parent(tree, L[(I[xid] & HIGH_BITS(k+1)) | (1 << k)]); } IF_STATS(lca->num_compares++); // Step 4. l = h(A[yid]); if (l == j) { ybar = y; } else { k = MSB(A[yid] & ~HIGH_BITS(j)); ybar = stree_get_parent(tree, L[(I[yid] & HIGH_BITS(k+1)) | (1 << k)]); } IF_STATS(lca->num_compares++); // Step 5. IF_STATS(lca->num_compares++); return (stree_get_ident(tree, xbar) < stree_get_ident(tree, ybar)) ? xbar : ybar; }
int posix_fadvise(int fd, off_t offset, off_t len, int advise) { INTERNAL_SYSCALL_DECL (err); int ret = INTERNAL_SYSCALL (arm_fadvise64_64, err, 6, fd, advise, __LONG_LONG_PAIR (HIGH_BITS(offset), (long)offset), __LONG_LONG_PAIR (HIGH_BITS(len), (long)len)); if (INTERNAL_SYSCALL_ERROR_P (ret, err)) return INTERNAL_SYSCALL_ERRNO (ret, err); return 0; }