Package xbird.util.collections.ints.Int2IntHash

Examples of xbird.util.collections.ints.Int2IntHash.Int2IntLRUMap


    public void testInt2IntLruMap() {
        System.out.print("testInt2IntLruMap - ");
        System.gc();
        long free = SystemUtils.getHeapFreeMemory();
        System.out.print("free(init): " + free);
        Int2IntLRUMap ilru = new Int2IntLRUMap(LIMIT);
        for(int i = 0; i < LOOP; i++) {
            ilru.put(i, i);
        }
        Random random = new Random();
        for(int i = 0; i < LOOP / 2; i++) {
            int r = random.nextInt(LOOP - 1);
            ilru.put(r, r);
        }
        long used = free - SystemUtils.getHeapFreeMemory();
        System.out.print(", used(before GC): " + used);
        System.gc();
        used = free - SystemUtils.getHeapFreeMemory();
View Full Code Here


    }

    @Test
    public void testPut() {
        final int limit = 4;
        Int2IntLRUMap lru = new Int2IntLRUMap(4);
        lru.put(0, 1);
        lru.put(1, 2);
        lru.put(2, 3);
        lru.put(3, 4);
        Assert.assertEquals(4, lru.put(3, 5));
        Assert.assertEquals(-1, lru.put(4, 5));
        Assert.assertEquals(limit, lru.size());
    }
View Full Code Here

        Assert.assertEquals(limit, lru.size());
    }

    @Test
    public void testGetPromotion() {
        Int2IntLRUMap map = new Int2IntLRUMap(3);
        map.put(1, 1);
        map.put(2, 2);
        map.put(3, 3);
        // eviction order is now 1,2,3      
        map.get(1);
        // eviction order is now 2,3,1
        map.put(4, 4);
        // 2 should be evicted (then 3,1,4)
        int[] keys = new int[3];
        int i = 0;
        for(Int2IntHash.BucketEntry e : map) {
            keys[i++] = e.key;
View Full Code Here

TOP

Related Classes of xbird.util.collections.ints.Int2IntHash.Int2IntLRUMap

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.