package mikera.indexz;
import java.util.ArrayList;
import java.util.List;
import mikera.util.Rand;
/**
* Class for static index methods
*
* @author Mike
*
*/
public class Indexz {
private Indexz(){}
public static Index create(List data) {
int length=data.size();
Index result=new Index(length);
for (int i=0; i0; j--) {
result.swap(Rand.r(j+1), j);
}
return result;
}
public static Index createRandomChoice(int count, int max) {
Index result=createSequence(count);
Rand.chooseIntegers(result.data, 0, count, max);
assert(result.isDistinct()&&result.isSorted());
return result;
}
public static Index createRandomChoice(int count, Index source) {
Index result=createSequence(count);
Rand.chooseIntegers(result.data, 0, count, source.length());
assert(result.isDistinct()&&result.isSorted());
result.lookupWith(source);
return result;
}
/**
* Returns a random subset of an Index, including each element with the given probability
* @param probability
* @return
*/
public static Index createRandomSubset(AIndex index, double probability) {
int len=index.length();
// estimated capacity required = 3 standard deviations
int elen=(int)(len*probability+3.0*Math.sqrt(len*probability*(1-probability)));
ArrayList al=new ArrayList(elen);
for (int i=0; i
Ads help maintain this website.