Ejemplo n.º 1
0
char *test_set()
{
  Array_set(array, 0, val1);
  Array_set(array, 1, val2);

  return NULL;
}
Ejemplo n.º 2
0
// Same as the map function above, but also updates the values of the
// input array.
void RoomyList_mapAndModify(RoomyList *rl,
                     void (*mapFunc)(void* oldVal, void* newValOut)) {
    // if list is locally empty, return without mapping
    if(rl->lSize == 0) return;

    char listFile[RGLO_STR_SIZE];
    RoomyList_getListFileName(rl, RGLO_MY_RANK, listFile);
    uint64 bytesLeft = numBytesInFile(listFile);
    uint64 chunkSize = RGLO_BUFFER_SIZE;
    chunkSize = chunkSize - (chunkSize % rl->bytesPer);
    uint64 arraySize = chunkSize / rl->bytesPer;
    Array chunk = Array_make(rl->bytesPer, arraySize);
    FILE* f = fopen(listFile, "a+");
    uint64 filePos = 0;
    void* newVal = malloc(rl->bytesPer);
    while(bytesLeft) {
        // load chunk
        uint64 curChunkSize = chunkSize;
        if(curChunkSize > bytesLeft) curChunkSize = bytesLeft;
        uint64 curArraySize = curChunkSize / rl->bytesPer;
        fseek(f, filePos, SEEK_SET);
        Array_fileDescLoad(&chunk, f, curArraySize);

        // apply map function, with modifications
        int i;
        for(i=0; i<curArraySize; i++) {
            mapFunc(Array_get(&chunk, i), newVal);
            
            // keep track of predicate changes
            int p;
            for(p=0; p<rl->numPredicates; p++) {
                rl->predicateVals[p] += rl->predFuncs[p](newVal) -
                                        rl->predFuncs[p](Array_get(&chunk, i));
            }

            Array_set(&chunk, i, newVal);
        }

        // save chunk
        fseek(f, filePos, SEEK_SET);
        Array_fileDescSave(&chunk, f, curArraySize);
        
        filePos += curChunkSize;
        bytesLeft -= curChunkSize;
    }
    
    // clean up
    Array_destroy(&chunk);
    free(newVal);
    fclose(f);
}
Ejemplo n.º 3
0
/**
 * 指定サイズの部分文字列で、2つ以上存在するものの位置をビット配列にセットする
 *
 * @param source 文字列全体
 * @param dest 出力先ビット列
 * @param oldBits 前回検索時のビット列
 * @param len 部分文字列の長さ
 * @param hash ハッシュテーブル
 *
 * @return 一致する部分文字列があればR_OK。なければR_NOTFOUND
 */
Result scanSameSubstrings(const Array *source, Array *dest, const Array *oldBits, size_t len, Hash *hash)
{
    size_t slen = source->length - len + 1;
    size_t i = 0;
    size_t j = 0;
    int found = 0;
    Result result = R_NG;

    Hash_clear(hash);

    /* 指定サイズの全部分文字列について、ハッシュを使用して重複しているものを洗い出す */
    for(i = 0; i < (slen - 1); ++i) {
        const char *p;
        const HashEntry *before = NULL;

        /* 前回検査時の重複文字列の位置でなければスキップ */
        if(!Array_get(oldBits, i)) {
            continue;
        }

        /* 現在位置の部分文字列が重複しているか検査する。未登録であればハッシュに登録する */
        p = Array_pointer(source, i);
        if(Hash_putIfAbsent(hash, p, len, &before) != R_OK) {
            return R_NG;
        }

        /* 重複している部分文字列だった場合、以前と今回の出現箇所のビットを立てる */
        if(before) {
            Array_set(dest, before->p - (const char *)source->p, 1);
            Array_set(dest, i, 1);
            found = 1;
        }
    }

    return found ? R_OK : R_NOTFOUND;
}
Ejemplo n.º 4
0
void testArray() {
    int n = 100;
    // make
    Array a = Array_make(sizeof(int), n);
    
    // set and get
    int i;
    for(i=0; i<n; i++) {
        Array_set(&a, i, &i);
    }
    for(i=0; i<n; i++) {
        int* val = (int*)Array_get(&a, i);
        assert(*val == i);
    }

    // save and load
    char* fname = "/tmp/test.array";
    Array_fileSave(&a, fname);
    Array b = Array_make(sizeof(int), n);
    Array_fileLoad(&b, fname);
    for(i=0; i<n; i++) {
        int* val = (int*)Array_get(&b, i);
        assert(*val == i);
    }

    // make init
    int buf[n];
    for(i=0; i<n; i++) {
        buf[i] = i;
    }
    Array c = Array_makeInit(sizeof(int), n, &buf);
    for(i=0; i<n; i++) {
        int* val = (int*)Array_get(&c, i);
        assert(*val == i);
    }

    Array_destroy(&a);
    Array_destroy(&b);
    Array_destroy(&c);

    printf("ARRAY PASSED TESTS\n");
}