Permalink
Browse files

Work-in-progress

  • Loading branch information...
1 parent d1b4d58 commit 4f3cda03c34eea8e4bf7e860edfa62f374508145 Andy Seaborne committed Mar 18, 2012
@@ -57,27 +57,29 @@ public static void main(String ...argv)
print = false ;
{
- byte[] keyStart = { 2 , 4 , 6 } ;
+ byte[] k1 = { 0 , 2 } ;
+ byte[] k2 = { 0 , 4 } ;
+ byte[] k3 = { 0 , 2 , 4 , 6 } ;
+
+ byte[] k4 = { 0 , 2 , 4 , 5 } ;
+ byte[] k5 = { 0 , 1 } ;
+
+ byte[] keyStart = { 0 ,2 , 4} ;
byte[] keyFinish = null ;
- RadixTree t = tree(key1, key2, key3, key4, key5, key6) ;
+ RadixTree t = tree(k1,k2,k3) ;
RadixTree.logging = true ;
- testIter(t, keyStart, keyFinish, key1, key4, key2) ;
- RadixTree.logging = false ;
- }
-
- {
- byte[] keyStart = null ;
- byte[] keyFinish = { 2 , 4 , 6 } ;
- RadixTree t = tree(key1, key2, key3, key4, key5, key6) ;
- RadixTree.logging = true ;
- testIter(t, keyStart, keyFinish, key6, key3, key5) ;
+
+ Iterator<RadixEntry> iter = t.iterator(keyStart, keyFinish) ;
+ for ( ; iter.hasNext() ; )
+ System.out.println(iter.next()) ;
+
+ //testIter(t, keyStart, keyFinish, k2, k3) ;
RadixTree.logging = false ;
}
System.exit(0) ;
-
if ( true )
{
byte[] k1 = { 1 , 2 , 3 } ;
@@ -146,7 +148,7 @@ private static void testIter(RadixTree t, byte[] keyStart, byte[] keyFinish, byt
if ( ! iter.hasNext() ) throw new RuntimeException("Iterator ran out") ;
byte[] k = iter.next().key ;
if ( 0 != Bytes.compare(results[i], k) )
- throw new RuntimeException("Arrays differ: "+RLib.str(results[i])+" : "+RLib.str(k)) ;
+ throw new RuntimeException("Arrays differ: "+Str.str(results[i])+" : "+Str.str(k)) ;
}
if ( ! iter.hasNext() ) throw new RuntimeException("Iterator still has elements") ;
}
@@ -157,7 +159,7 @@ static private RadixTree tree(RadixTree t, byte[] ... keys)
{
byte[] k = keys[i] ;
byte[] v = valFromKey(k) ;
- if (print) System.out.println("Build: "+RLib.str(k)) ;
+ if (print) System.out.println("Build: "+Str.str(k)) ;
t.insert(k,v) ;
if (print) t.print() ;
t.check() ;
@@ -35,43 +35,10 @@ public Record convert(RadixEntry item)
return new Record(item.key, item.value) ;
}} ;
- public static String str(ByteBuffer bytes)
- {
- StringBuilder sb = new StringBuilder() ;
- char sep = 0 ;
- for ( int i = bytes.position() ; i < bytes.limit() ; i++ )
- {
- byte b = bytes.get(i) ;
- if ( sep != 0 )
- sb.append(sep) ;
- else
- sep = ' ' ;
-
- sb.append(String.format("%02X", b)) ;
- }
- return sb.toString() ;
- }
-
- public static String str(byte[] bytes)
- { return str(bytes, " ") ; }
-
-
- public static String str(byte[] bytes, String sep)
- {
- if ( bytes == null )
- return "" ;
- StringBuilder sb = new StringBuilder() ;
- boolean first = true ;
- for ( byte b : bytes )
- {
- if ( ! first )
- sb.append(sep) ;
- first = false ;
- sb.append(String.format("0x%02X", b)) ;
- }
- return sb.toString() ;
- }
-
+ // Collect all str(X) into a single class
+ // See also ByteBufferLib
+ // Bytes, Chars, StrUtils.
+
private static String str(RadixTree rt)
{
Iterator<String> iter = Iter.map(rt.iterator(), new Transform<RadixEntry, String>(){
@@ -35,9 +35,9 @@ public RadixEntry(byte[] key, byte[] value)
public String toString()
{
if ( value == null )
- return "["+RLib.str(key)+"]" ;
+ return "["+Str.str(key)+"]" ;
else
- return "["+RLib.str(key)+":"+RLib.str(value)+"]" ;
+ return "["+Str.str(key)+" :: "+Str.str(value)+"]" ;
}
}
Oops, something went wrong.

0 comments on commit 4f3cda0

Please sign in to comment.