Package xerial.larray

Examples of xerial.larray.LIntArray


    Logger _logger = new Logger(this.getClass());

    @Test
    public void constructor() {

        LIntArray l = LArrayJ.newLIntArray(5L);
        for (long i = 0; i < l.size(); ++i) l.update(i, (int) i * 2);
        _logger.debug(l.mkString(", "));
        for (long i = 0; i < l.size(); ++i) l.update(i, (int) (i * i));
        _logger.debug(l.mkString(", "));

        Assert.assertEquals(5L, l.size());

        l.free();
    }
View Full Code Here


    @Test
    public void testCompress() throws Exception {

        long N = 100000000L;
        LIntArray l = LArrayJ.newLIntArray(N);
        for (int i = 0; i < N; i++) {
            l.update(i, (int) (Math.toDegrees(Math.sin(i / 360))));
        }
        for (int iter = 0; iter < 10; iter++) {
            long sum = 0;
            long start = System.currentTimeMillis();
            for (int i = 0; i < l.length(); i++) {
                sum += l.apply(i);
            }
            long end = System.currentTimeMillis();
            _logger.debug("time:" + (end - start) + " sum:" + sum);
        }
        _logger.debug("compressing the data");
        int maxLen = Snappy.maxCompressedLength((int) l.byteLength());
        LByteArray compressedBuf = LArrayJ.newLByteArray(maxLen);
        long compressedLen = Snappy.rawCompress(l.address(), l.byteLength(),
                compressedBuf.address());
        LByteArray compressed = (LByteArray) compressedBuf.slice(0,
                compressedLen);
        File f = File.createTempFile("snappy", ".dat", new File("target"));
        f.deleteOnExit();
        compressed.saveTo(f);

        _logger.debug("decompressing the data");
        long T1 = System.currentTimeMillis();
        MappedLByteArray b = LArrayJ.mmap(f, 0, f.length(), MMapMode.READ_ONLY);
        long T2 = System.currentTimeMillis();

        long len = Snappy.uncompressedLength(b.address(), b.length());
        LIntArray decompressed = LArrayJ.newLIntArray(len / 4);
        Snappy.rawUncompress(b.address(), b.length(), decompressed.address());
        long T3 = System.currentTimeMillis();
        _logger.debug("Map time:" + (T2 - T1));
        _logger.debug("decompress time:" + (T3 - T2));


        _logger.debug("Summing decompressed array");
        for (int iter = 0; iter < 10; iter++) {
            long sum = 0;
            long start = System.currentTimeMillis();
            for (int i = 0; i < decompressed.length(); i++) {
                sum += decompressed.apply(i);
            }
            long end = System.currentTimeMillis();
            _logger.debug("time:" + (end - start) + " sum:" + sum);
        }
    }
View Full Code Here

*/
public class LArrayJavaExample {

    public static void main(String[] args) {
        // Create a new LArray of Int type
        LIntArray l = LArrayJ.newLIntArray(5);

        // Read elements
        int e0 = l.apply(0);
        int e1 = l.apply(1);

        // Set elements
        for(int i=0; i<l.size(); ++i)
            l.update(i, i);

        // print the elements
        System.out.println(l.mkString(", "));

        // Traverse the elements
        int index = 0;
        for(Object e : l.ji()) {
            System.out.println(String.format("l(%d) = %d", index, (Integer)e));
            index += 1;
        }

        // manipulate LArray
        LIterator<?> l2 = l.map(new AbstractFunction1<Object, Object>(){
            public Object apply(Object v1) {
                return Integer.class.cast(v1) * 10;
            }
        });
        LIterator<?> f = l.filter(new AbstractFunction1<Object, Object>(){
            public Object apply(Object v1) {
                return Integer.class.cast(v1) % 2 == 0;
            }
        });
        LArray s = l.slice(2);

        // Build LArray
        LIntArrayBuilder b = new LIntArrayBuilder();
        for(int i=0; i<10; i += 3)
            b.append(i);
        LIntArray lb = b.result(); // LArray(0, 3, 6, 9)
        System.out.println(lb.mkString(", "));

        // Save to a file
        File file = l.saveTo(new File("target/larray.tmp"));
        file.deleteOnExit();

View Full Code Here

TOP

Related Classes of xerial.larray.LIntArray

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.