package com.meidusa.amoeba.sqljep.function;
import com.meidusa.amoeba.sqljep.function.PostfixCommand;
import com.meidusa.amoeba.sqljep.ASTFunNode;
import com.meidusa.amoeba.sqljep.JepRuntime;
import com.meidusa.amoeba.sqljep.ParseException;
/**
*
* @author struct
*
*/
public class Hash extends PostfixCommand {
final public int getNumberOfParameters() {
return 1;
}
public Comparable<?>[] evaluate(ASTFunNode node, JepRuntime runtime) throws ParseException {
node.childrenAccept(runtime.ev, null);
Comparable<?> param = runtime.stack.pop();
return new Comparable<?>[]{param};
}
public static Comparable<?> hash(Comparable<?> param) throws ParseException {
if (param == null) {
return null;
}
return param.hashCode();
}
public Comparable<?> getResult(Comparable<?>... comparables)
throws ParseException {
return hash(comparables[0]);
}
public static void main(String[] args){
String dd = "624265432";
int off = 0;
char val[] = dd.toCharArray();
int len = val.length;
int h = 0;
for (int i = 0; i < len; i++) {
h = 31*h + val[off++];
}
try {
System.out.println(hash((dd)));
} catch (ParseException e) {
e.printStackTrace();
}
}
}