Package com.onionnetworks.fec

Examples of com.onionnetworks.fec.PureCode


  public void testBenchmark() {
    if(!TestProperty.BENCHMARK) return;

    int lim = fecMath.gfSize + 1;
    FECCode maybeNative = FECCodeFactory.getDefault().createFECCode(KK, lim);
    FECCode pureCode = new PureCode(KK, lim);
    int[] index = new int[KK];

    for (int i = 0; i < KK; i++)
      index[i] = lim - i - 1;

    byte[] src = new byte[KK * PACKET_SIZE];
    Util.rand.nextBytes(src);
    Buffer[] srcBufs = new Buffer[KK];
    for (int i = 0; i < srcBufs.length; i++)
      srcBufs[i] = new Buffer(src, i * PACKET_SIZE, PACKET_SIZE);

    byte[] repair = new byte[KK * PACKET_SIZE];
    Buffer[] repairBufs = new Buffer[KK];
    for (int i = 0; i < repairBufs.length; i++) {
      repairBufs[i] = new Buffer(repair, i * PACKET_SIZE, PACKET_SIZE);
    }

    int[] indexBackup = new int[index.length];
    System.arraycopy(index,0,indexBackup,0,index.length);

    System.out.println("Getting ready for benchmarking encode()");
    long t1 = System.currentTimeMillis();
    maybeNative.encode(srcBufs, repairBufs, index);
    long t2 = System.currentTimeMillis();
    pureCode.encode(srcBufs, repairBufs, indexBackup);
    long t3 = System.currentTimeMillis();

    float dNativeEncode = t2 - t1;
    float dPureEncode = t3 - t2;

    Buffer[] repairBufs2 = repairBufs.clone();
    System.arraycopy(repairBufs, 0, repairBufs2, 0, repairBufs.length);
    System.out.println("Getting ready for benchmarking decode()");
    t1 = System.currentTimeMillis();
    maybeNative.decode(repairBufs, index);
    t2 = System.currentTimeMillis();
    pureCode.decode(repairBufs2, indexBackup);
    t3 = System.currentTimeMillis();

    float dNativeDecode = t2 - t1;
    float dPureDecode = t3 - t2;

View Full Code Here


  }

  public void testSimpleRev() {
    int lim = fecMath.gfSize + 1;
    FECCode code = FECCodeFactory.getDefault().createFECCode(KK, lim);
    FECCode code2 = new PureCode(KK, lim);
    int[] index = new int[KK];

    for (int i = 0; i < KK; i++)
      index[i] = lim - i - 1;
View Full Code Here

  }

  public void testSimple() {
    int lim = fecMath.gfSize + 1;
    FECCode code = FECCodeFactory.getDefault().createFECCode(KK, lim);
    FECCode code2 = new PureCode(KK, lim);
    int[] index = new int[KK];

    for (int i = 0; i < KK; i++)
      index[i] = KK - i;
    encodeDecode(code, code2, index);
View Full Code Here

  }

  public void testShifted() {
    int lim = fecMath.gfSize + 1;
    FECCode code = FECCodeFactory.getDefault().createFECCode(KK, lim);
    FECCode code2 = new PureCode(KK, lim);
    int[] index = new int[KK];

    int max_i0 = KK / 2;
    if (max_i0 + KK > lim)
      max_i0 = lim - KK;
View Full Code Here

    @Override
    public void decode(byte[][] dataBlocks, byte[][] checkBlocks, boolean[] dataBlocksPresent, boolean[] checkBlocksPresent, int blockLength) {
        int k = dataBlocks.length;
        int n = dataBlocks.length + checkBlocks.length;
        PureCode codec = getCodec(k, n);
        int[] blockNumbers = new int[k];
        Buffer[] buffers = new Buffer[k];
        // The data blocks are already in the correct positions in dataBlocks.
        for(int i=0;i<dataBlocks.length;i++) {
            if(dataBlocks[i].length != blockLength) throw new IllegalArgumentException();
            if(!dataBlocksPresent[i]) continue;
            buffers[i] = new Buffer(dataBlocks[i], 0, blockLength);
            blockNumbers[i] = i;
        }
        int target = 0;
        // Fill in the gaps with the check blocks.
        for(int i=0;i<checkBlocks.length;i++) {
            if(!checkBlocksPresent[i]) continue;
            if(checkBlocks[i].length != blockLength) throw new IllegalArgumentException();
            while(target < dataBlocks.length && buffers[target] != null) target++; // Scan for slot.
            if(target >= dataBlocks.length) continue;
            // Decode into the slot for the relevant data block.
            buffers[target] = new Buffer(dataBlocks[target]);
            // Provide the data from the check block.
            blockNumbers[target] = i + dataBlocks.length;
            System.arraycopy(checkBlocks[i], 0, dataBlocks[target], 0, blockLength);
        }
       
        // Now do the decode.
        codec.decode(buffers, blockNumbers);
        // The data blocks are now decoded and in the correct locations.
    }
View Full Code Here

                break;
            }
        }
        codeRef = recentlyUsedCodecs.get(key);
        if(codeRef != null) {
            PureCode code = codeRef.get();
            if(code != null) {
                recentlyUsedCodecs.push(key, codeRef);
                return code;
            }
        }
        PureCode code = new PureCode(k, n);
        recentlyUsedCodecs.push(key, new SoftReference<PureCode>(code));
        return code;
    }
View Full Code Here

    @Override
    public void encode(byte[][] dataBlocks, byte[][] checkBlocks, boolean[] checkBlocksPresent,
            int blockLength) {
        int k = dataBlocks.length;
        int n = dataBlocks.length + checkBlocks.length;
        PureCode codec = getCodec(k, n);
        Buffer[] data = new Buffer[dataBlocks.length];
        for(int i=0;i<data.length;i++) {
            if(dataBlocks[i] == null || dataBlocks[i].length != blockLength)
                throw new IllegalArgumentException();
            data[i] = new Buffer(dataBlocks[i]);
        }
        int mustEncode = 0;
        for(int i=0;i<checkBlocks.length;i++) {
            if(checkBlocks[i] == null || checkBlocks[i].length != blockLength)
                throw new IllegalArgumentException();
            if(!checkBlocksPresent[i]) mustEncode++;
        }
        Buffer[] check = new Buffer[mustEncode];
        if(mustEncode == 0) return; // Done already.
        int[] toEncode = new int[mustEncode];
        int x = 0;
        for(int i=0;i<checkBlocks.length;i++) {
            if(checkBlocksPresent[i]) continue;
            check[x] = new Buffer(checkBlocks[i]);
            toEncode[x++] = i+dataBlocks.length;
        }
        codec.encode(data, check, toEncode);
    }
View Full Code Here

TOP

Related Classes of com.onionnetworks.fec.PureCode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.