From now on always Hash.
l=1000000;//number for testing speed on load and search
TN loaded
MAP loaded
Tabl loaded
Tn founded : 476
Map founded : 476
Table founded : 476
TN Load: 48061 Search: 1256 millis !!!!!!!!!!!!!!!!!!!!!!!! XXXXXXXXX
MAP Load: 2655 Search: 83 millis asychronized
TABLE Load: 1928 Search: 94 millis sychronized
I knew for my bad load time but didnt knew for my bad search time.
I discovered together with a test on reflection.
Reflection test on calling method meth(float f){}.invoke()
instead of using a interface meth(float f);
came bad for reflection.
About 6 times up the reflection execution
------------------------------------------------
Just for my history .
/*
* Tsoukalas I. Dimitrios
* jimakoskx@{hotmail.com,facebook.com,gmail.com,blogspot.com}
*/
package jel.lib.dd.tr;
import java.io.PrintStream;
import java.lang.reflect.Array;
import java.util.Comparator;
import java.util.Iterator;
import java.util.StringTokenizer;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
/**
*
* @author zojimis
*/
public class Tn extends Dmtn{
public static void main(String[] args) {
Tn t=new Tn("start test");
String ar[]={"1","2"};
t.fad(1);
t.fad(4);
t.fad(7);
int ind=t.ioi(-9);
System.out.println(""+ind);
if(ind<0){
System.out.println("Decoded="+t._x_de_code_(ind));
}
}
public Tn(){
super();
//System.out.println("C:Tn()");
}
public Tn(Object uo){
super(uo);
//System.out.println("C:Tn(Object)");
}
public Tn(Object uo,boolean allowsChild){
super(uo,allowsChild);
//System.out.println("C:Tn(Object , boolean)");
}
public Tn cr(Object uo){return new Tn(uo);}
public Tn tn(int index){return (Tn)getChildAt(index);}
public double comp(Tn other){
//System.out.println("Comparing "+other.getClass()+"\nwith "+getClass());
return ((Comparable)userObject).compareTo((Comparable)other.userObject);
//return userObject.toString().compareTo(other.getUserObject().toString());
//return ((Integer)getUserObject()).intValue()-((Integer)other.getUserObject()).intValue();
}
/**
* ++index;index=-index;
* @param index
* @return
*/
public int _x_de_code_(int index){
//System.out.print("Decoding:"+index);
++index;
index=-index;
//System.out.println("......as :"+index);
return index;
}
/**
* index=-index;--index;
* @param index
* @return
*/
public int _x_en_code_(int index){
//System.out.print("Encoding:"+index);
index=-index;
--index;
//System.out.println("......as :"+index);
return index;
}
/**
* IN TESTING MODE YET
*
* Index Or Insertion index (decoded)
* toCompare.comp(it);
* @param toCompare
* @return
*/
public int ioi(Tn toCompare){//steps=0;
int lo = 0,hi = getChildCount() - 1,mid;double d;Tn it;
while (lo <= hi) {mid = lo + (hi - lo) / 2;
it=(Tn)getChildAt(mid);
//System.out.println(toCompare.getClass().getSimpleName()+"comp("+it.getClass().getSimpleName());
d=toCompare.comp(it);
if(d<0.0){hi = mid - 1;}
else if (d>0.0){lo = mid + 1;}
else {return mid;}//++steps;
}return _x_en_code_(lo);
}
/**
* Index Or Insertion index (decoded)
* toCompare.compareTo(it.userObject);
* @param toCompare
* @return
*/
public int ioi(Comparable toCompare){
int lo = 0,hi = getChildCount() - 1,mid; double d;Tn it;
while (lo <= hi) {mid = lo + (hi - lo) / 2;
it=(Tn)getChildAt(mid);d=toCompare.compareTo(it.userObject);
if(d<0.0){ hi = mid - 1;}
else if (d>0.0){lo = mid + 1;}
else {return mid;}
}return _x_en_code_(lo);
}
/////////////// ADDING FUNCTIONS
//Node compare mode
public Tn nfad(Tn toCompareOrAddIfNotFounded){
//System.out.println(""+getChildCount());
int binarySearch=Tn.this.ioi(toCompareOrAddIfNotFounded);
if(binarySearch>-1){ return ((Tn)getChildAt(binarySearch));}
else{
super.insert(toCompareOrAddIfNotFounded, _x_de_code_(binarySearch));
return toCompareOrAddIfNotFounded;
}
}
///////////............................................more
//UserObjects as Comparables Search mode
public Tn f(Comparable toCompareOrCreateAddIfNotFounded){
int binarySearch=ioi(toCompareOrCreateAddIfNotFounded);
if(binarySearch>-1){return ((Tn)getChildAt(binarySearch));}
else{return null;}
}
public Tn fad(Comparable toCompareOrCreateAddIfNotFounded){
int binarySearch=ioi(toCompareOrCreateAddIfNotFounded);
if(binarySearch>-1){return ((Tn)getChildAt(binarySearch));}
else{
Tn nn=(Tn)cr(toCompareOrCreateAddIfNotFounded);
super.insert(nn, _x_de_code_(binarySearch));
return nn;
}
}
public Tn fadmIn(Iterator<Comparable> toCompareOrCreateAddIfNotFounded){
Tn out=this;
while(toCompareOrCreateAddIfNotFounded.hasNext()){
Tn newn=out.fad(toCompareOrCreateAddIfNotFounded.next());
out=newn;
}
return out;
}
public Tn fadmInCharactersAsStrings(String toCompareOrCreateAddIfNotFounded,String resetOnRootChars,String addBeforeReset){
Tn out=this;
int i=0;
int l=toCompareOrCreateAddIfNotFounded.length();
char ch;
while(i<l){
ch=toCompareOrCreateAddIfNotFounded.charAt(i);
if(resetOnRootChars.contains(ch+"")){
out.fad(addBeforeReset);
out=this;
}
else{
Tn newn=out.fad(ch+"");
out=newn;
}
++i;
}
return out;
}
public Tn fadmIn(StringTokenizer toCompareOrCreateAddIfNotFounded){
Tn out=this;
while(toCompareOrCreateAddIfNotFounded.hasMoreTokens()){
Tn newn=out.fad(toCompareOrCreateAddIfNotFounded.nextToken());
out=newn;
}
return out;
}
public Tn fadmInByStringsOfArray(Object array){
Tn out=this;
int i=0;
int l=Array.getLength(array);
while(i<l){
out=out.fad(Array.get(array, i)+"");
++i;
}
return out;
}
public Tn fadm(Iterator<Comparable> toCompareOrCreateAddIfNotFounded){
Tn out=this;
while(toCompareOrCreateAddIfNotFounded.hasNext()){
out=fad(toCompareOrCreateAddIfNotFounded.next());
}
return out;
}
public Tn fadm(StringTokenizer toCompareOrCreateAddIfNotFounded){
Tn out=this;
while(toCompareOrCreateAddIfNotFounded.hasMoreTokens()){
out=fad(toCompareOrCreateAddIfNotFounded.nextToken());
}
return out;
}
public Tn fadmByStringsOfArray(Object array){
Tn out=this;
int i=0;
int l=Array.getLength(array);
while(i<l){
out=fad(Array.get(array, i)+"");
++i;
}
return out;
}
}
l=1000000;//number for testing speed on load and search
TN loaded
MAP loaded
Tabl loaded
Tn founded : 476
Map founded : 476
Table founded : 476
TN Load: 48061 Search: 1256 millis !!!!!!!!!!!!!!!!!!!!!!!! XXXXXXXXX
MAP Load: 2655 Search: 83 millis asychronized
TABLE Load: 1928 Search: 94 millis sychronized
I knew for my bad load time but didnt knew for my bad search time.
I discovered together with a test on reflection.
Reflection test on calling method meth(float f){}.invoke()
instead of using a interface meth(float f);
came bad for reflection.
About 6 times up the reflection execution
------------------------------------------------
Just for my history .
/*
* Tsoukalas I. Dimitrios
* jimakoskx@{hotmail.com,facebook.com,gmail.com,blogspot.com}
*/
package jel.lib.dd.tr;
import java.io.PrintStream;
import java.lang.reflect.Array;
import java.util.Comparator;
import java.util.Iterator;
import java.util.StringTokenizer;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
/**
*
* @author zojimis
*/
public class Tn extends Dmtn{
public static void main(String[] args) {
Tn t=new Tn("start test");
String ar[]={"1","2"};
t.fad(1);
t.fad(4);
t.fad(7);
int ind=t.ioi(-9);
System.out.println(""+ind);
if(ind<0){
System.out.println("Decoded="+t._x_de_code_(ind));
}
}
public Tn(){
super();
//System.out.println("C:Tn()");
}
public Tn(Object uo){
super(uo);
//System.out.println("C:Tn(Object)");
}
public Tn(Object uo,boolean allowsChild){
super(uo,allowsChild);
//System.out.println("C:Tn(Object , boolean)");
}
public Tn cr(Object uo){return new Tn(uo);}
public Tn tn(int index){return (Tn)getChildAt(index);}
public double comp(Tn other){
//System.out.println("Comparing "+other.getClass()+"\nwith "+getClass());
return ((Comparable)userObject).compareTo((Comparable)other.userObject);
//return userObject.toString().compareTo(other.getUserObject().toString());
//return ((Integer)getUserObject()).intValue()-((Integer)other.getUserObject()).intValue();
}
/**
* ++index;index=-index;
* @param index
* @return
*/
public int _x_de_code_(int index){
//System.out.print("Decoding:"+index);
++index;
index=-index;
//System.out.println("......as :"+index);
return index;
}
/**
* index=-index;--index;
* @param index
* @return
*/
public int _x_en_code_(int index){
//System.out.print("Encoding:"+index);
index=-index;
--index;
//System.out.println("......as :"+index);
return index;
}
/**
* IN TESTING MODE YET
*
* Index Or Insertion index (decoded)
* toCompare.comp(it);
* @param toCompare
* @return
*/
public int ioi(Tn toCompare){//steps=0;
int lo = 0,hi = getChildCount() - 1,mid;double d;Tn it;
while (lo <= hi) {mid = lo + (hi - lo) / 2;
it=(Tn)getChildAt(mid);
//System.out.println(toCompare.getClass().getSimpleName()+"comp("+it.getClass().getSimpleName());
d=toCompare.comp(it);
if(d<0.0){hi = mid - 1;}
else if (d>0.0){lo = mid + 1;}
else {return mid;}//++steps;
}return _x_en_code_(lo);
}
/**
* Index Or Insertion index (decoded)
* toCompare.compareTo(it.userObject);
* @param toCompare
* @return
*/
public int ioi(Comparable toCompare){
int lo = 0,hi = getChildCount() - 1,mid; double d;Tn it;
while (lo <= hi) {mid = lo + (hi - lo) / 2;
it=(Tn)getChildAt(mid);d=toCompare.compareTo(it.userObject);
if(d<0.0){ hi = mid - 1;}
else if (d>0.0){lo = mid + 1;}
else {return mid;}
}return _x_en_code_(lo);
}
/////////////// ADDING FUNCTIONS
//Node compare mode
public Tn nfad(Tn toCompareOrAddIfNotFounded){
//System.out.println(""+getChildCount());
int binarySearch=Tn.this.ioi(toCompareOrAddIfNotFounded);
if(binarySearch>-1){ return ((Tn)getChildAt(binarySearch));}
else{
super.insert(toCompareOrAddIfNotFounded, _x_de_code_(binarySearch));
return toCompareOrAddIfNotFounded;
}
}
///////////............................................more
//UserObjects as Comparables Search mode
public Tn f(Comparable toCompareOrCreateAddIfNotFounded){
int binarySearch=ioi(toCompareOrCreateAddIfNotFounded);
if(binarySearch>-1){return ((Tn)getChildAt(binarySearch));}
else{return null;}
}
public Tn fad(Comparable toCompareOrCreateAddIfNotFounded){
int binarySearch=ioi(toCompareOrCreateAddIfNotFounded);
if(binarySearch>-1){return ((Tn)getChildAt(binarySearch));}
else{
Tn nn=(Tn)cr(toCompareOrCreateAddIfNotFounded);
super.insert(nn, _x_de_code_(binarySearch));
return nn;
}
}
public Tn fadmIn(Iterator<Comparable> toCompareOrCreateAddIfNotFounded){
Tn out=this;
while(toCompareOrCreateAddIfNotFounded.hasNext()){
Tn newn=out.fad(toCompareOrCreateAddIfNotFounded.next());
out=newn;
}
return out;
}
public Tn fadmInCharactersAsStrings(String toCompareOrCreateAddIfNotFounded,String resetOnRootChars,String addBeforeReset){
Tn out=this;
int i=0;
int l=toCompareOrCreateAddIfNotFounded.length();
char ch;
while(i<l){
ch=toCompareOrCreateAddIfNotFounded.charAt(i);
if(resetOnRootChars.contains(ch+"")){
out.fad(addBeforeReset);
out=this;
}
else{
Tn newn=out.fad(ch+"");
out=newn;
}
++i;
}
return out;
}
public Tn fadmIn(StringTokenizer toCompareOrCreateAddIfNotFounded){
Tn out=this;
while(toCompareOrCreateAddIfNotFounded.hasMoreTokens()){
Tn newn=out.fad(toCompareOrCreateAddIfNotFounded.nextToken());
out=newn;
}
return out;
}
public Tn fadmInByStringsOfArray(Object array){
Tn out=this;
int i=0;
int l=Array.getLength(array);
while(i<l){
out=out.fad(Array.get(array, i)+"");
++i;
}
return out;
}
public Tn fadm(Iterator<Comparable> toCompareOrCreateAddIfNotFounded){
Tn out=this;
while(toCompareOrCreateAddIfNotFounded.hasNext()){
out=fad(toCompareOrCreateAddIfNotFounded.next());
}
return out;
}
public Tn fadm(StringTokenizer toCompareOrCreateAddIfNotFounded){
Tn out=this;
while(toCompareOrCreateAddIfNotFounded.hasMoreTokens()){
out=fad(toCompareOrCreateAddIfNotFounded.nextToken());
}
return out;
}
public Tn fadmByStringsOfArray(Object array){
Tn out=this;
int i=0;
int l=Array.getLength(array);
while(i<l){
out=fad(Array.get(array, i)+"");
++i;
}
return out;
}
}
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου