Beispiel #1
0
rc_t KU64IndexOpen_v3(KU64Index_v3* self, struct KMMap const *mm, bool byteswap)
{
    rc_t rc = 0;
    const char* maddr;
    size_t msize;
    PBSTree* ptree = NULL;

    self->rc = 0;
    BSTreeInit(&self->tree);

    /* when opened for create, there will be no existing index */
    if( mm == NULL ) {
        return 0;
    }

    /* open the prior index in persisted mode */
    rc = KMMapAddrRead(mm, (const void**)&maddr);
    if( rc != 0 ) {
        return rc;
    }
    rc = KMMapSize(mm, &msize);
    if( rc != 0 ) {
        return rc;
    }
    if( msize <= sizeof(struct KIndexFileHeader_v3) ) {
        return 0;
    }

    rc = PBSTreeMake(&ptree, (const void**)(maddr + sizeof(struct KIndexFileHeader_v3)),
                     msize - sizeof(struct KIndexFileHeader_v3), byteswap);
    if( rc != 0 ) {
        return rc;
    }

    PBSTreeDoUntil(ptree, false, KU64Index_UnrollPersisted, self);
    rc = self->rc;

    PBSTreeWhack(ptree);

    if( rc != 0 ) {
        KU64IndexWhack_v3(self);
    }
    return rc;
}
Beispiel #2
0
rc_t get_a_sequence (param_block * pb)
{
    char * eol;
    rc_t rc = 0;
    if (pb->seq == NULL)        /* first call */
    {
        const void * annoying;
        uint64_t file_pos;
        size_t map_size;
        uint64_t file_size;

        rc = KFileSize (pb->file, &file_size);
        if (rc)
            return rc;

        rc = KMMapAddrRead (pb->mmap, &annoying);
        if (rc)
            return rc;

        pb->seq = annoying;

        if (pb->seq == NULL)
            return 0;

        rc = KMMapPosition (pb->mmap, &file_pos);
        if (rc)
            return rc;

        if (file_pos != 0)
        {
            rc = RC (rcExe, rcMemMap, rcAccessing, rcOffset, rcInvalid);
            return rc;
        }

        rc = KMMapSize (pb->mmap, &map_size);
        if (rc)
            return rc;

        if (map_size != file_size)
        {
            rc = RC (rcExe, rcMemMap, rcAccessing, rcFile, rcInvalid);
            return rc;
        }
        pb->eof = pb->seq + map_size;
    }
    else
    {
        pb->seq += pb->seq_size + 1;

        if (pb->seq >= pb->eof)
        {
            pb->seq = NULL;
            return 0;
        }
    }

    eol = string_chr (pb->seq, pb->eof - pb->seq, '\n');
    if (eol == NULL)
        pb->seq_size = pb->eof - pb->seq;
    else
        pb->seq_size = eol - pb->seq;

    return rc;
}