public void testBlukPut() throws Exception {
    File indexFile = new File("tmp/bulkput");
    indexFile.delete();

    DiskTreap<String, Integer> index = new DiskTreap<String, Integer>(indexFile);

    Map<String, Integer> map = new HashMap<String, Integer>();
    map.put("foo", 1);
    map.put("footbar", 2);
    map.put("azb", 3);
    map.put("dddddd", 4);
    map.put("aojiao", 5);

    Map<String, Integer> map2 = new HashMap<String, Integer>();
    map2.put("azb", 13);
    map2.put("footbar", 14);
    map2.put("sjy", 140);

    index.bulkPut(map);
    index.bulkPut(map2);
    index.close();

    index = new DiskTreap<String, Integer>(indexFile);
    assertEquals(index.prefix("a", 10).toString(), "{aojiao=5, azb=13}");
    assertEquals(index.prefix("f", 10).toString(), "{foo=1, footbar=14}");
    assertEquals(index.get("dddddd").toString(), "4");
    assertEquals(index.length(), 6);
    index.close();
  }
  public void testPrefix() throws Exception {

    DiskTreap<String, Integer> strKeyIndex = new DiskTreap<String, Integer>(prepareDataStringKey());

    Map<String, Integer> result = strKeyIndex.prefix("aa", 1);
    assertNotNull(result);
    assertEquals(1, result.size());
    assertEquals(123, (int) result.get("aab"));

    result = strKeyIndex.prefix("I", 1);
    assertNotNull(result);
    assertEquals(1, result.size());
    assertEquals(456, (int) result.get("IBM"));

    result = strKeyIndex.prefix("18", 1);
    assertNotNull(result);
    assertEquals(1, result.size());
    assertEquals(789, (int) result.get("18 year"));

    result = strKeyIndex.prefix("你好世", 1);
    assertNotNull(result);
    assertEquals(1, result.size());
    assertEquals(7777, (int) result.get("你好世界"));

    strKeyIndex.close();

    // =======

    /*DiskTreap<Integer, String> intKeyIndex = new DiskTreap<Integer, String>(prepareDataFastIntKey());

    Map<Integer, String> result_2 = intKeyIndex.prefix(-12, 1) ;
    assertNotNull(result_2) ;
    assertEquals(1, result_2.size()) ;
    System.out.println(result_2.size()) ;
    assertEquals("abc", result_2.get(-12)) ;

    result_2 = intKeyIndex.prefix(3, 1) ;
    assertNotNull(result_2) ;
    assertEquals(1, result_2.size()) ;
    System.out.println(result_2.size()) ;
    assertEquals("中国", result_2.get(345)) ;

    result_2 = intKeyIndex.prefix(0, 1) ;
    assertNotNull(result_2) ;
    assertEquals(1, result_2.size()) ;
    System.out.println(result_2.size()) ;
    assertEquals("zzz", result_2.get(0)) ;

    result_2 = intKeyIndex.prefix(13, 1) ;
    assertNotNull(result_2) ;
    assertEquals(1, result_2.size()) ;
    System.out.println(result_2.size()) ;
    assertEquals("def", result_2.get(133)) ;

    intKeyIndex.close();*/

    // =======

    DiskTreap<FastString, byte[]> fastStringIndex =
        new DiskTreap<FastString, byte[]>(prepareDataFastStringKey());

    Map<FastString, byte[]> result_3 = fastStringIndex.prefix(new FastString("aa"), 1);
    assertNotNull(result_3);
    assertEquals(1, result_3.size());
    assertEquals("123", new String(result_3.get(new FastString("aab"))));

    result_3 = fastStringIndex.prefix(new FastString("IB"), 1);
    assertNotNull(result_3);
    assertEquals(1, result_3.size());
    assertEquals("456", new String(result_3.get(new FastString("IBM"))));

    result_3 = fastStringIndex.prefix(new FastString("中科"), 1);
    assertNotNull(result_3);
    assertEquals(1, result_3.size());
    assertEquals("11789", new String(result_3.get(new FastString("中科院计算所"))));

    result_3 = fastStringIndex.prefix(new FastString("18"), 1);
    assertNotNull(result_3);
    assertEquals(1, result_3.size());
    assertEquals("你好", new String(result_3.get(new FastString("18 year"))));

    for (int i = 10; i <= 100; i++) {
      fastStringIndex.put(new FastString("" + i), (i + "").getBytes());
    }

    assertEquals(
        "[100, 10]",
        fastStringIndex
            .prefix(new FastString("1"), 5, new FastString("100"), false)
            .keySet()
            .toString());
    assertEquals(
        "[10, 100, 11, 12, 13, 14, 15]",
        fastStringIndex
            .prefix(new FastString("1"), 7, new FastString("10"), true)
            .keySet()
            .toString());
    fastStringIndex.close();
  }