Update List Functions

This commit is contained in:
Yasser 2020-04-13 11:46:33 -05:00
parent 6b89da98bb
commit 612413cf09
5 changed files with 6 additions and 28 deletions

View File

@ -30,15 +30,13 @@ public class ListHashed implements LongFunction<List<Object>> {
private final List<LongFunction<? extends Object>> valueFuncs; private final List<LongFunction<? extends Object>> valueFuncs;
private final int size; private final int size;
private final LongToIntFunction sizeFunc;
private final Hash hasher = new Hash(); private final Hash hasher = new Hash();
@Example({ @Example({
"ListFunctions(NumberNameToString(),NumberNameToString())", "ListFunctions(NumberNameToString(),NumberNameToString())",
"Create a list of ['one','one']" "Create a list of ['one','one']"
}) })
public ListHashed(LongToIntFunction sizeFunc, LongFunction<? extends Object>... funcs) { public ListHashed(LongFunction<? extends Object>... funcs) {
this.sizeFunc = sizeFunc;
this.valueFuncs = Arrays.asList(funcs); this.valueFuncs = Arrays.asList(funcs);
this.size = valueFuncs.size(); this.size = valueFuncs.size();
} }
@ -47,12 +45,11 @@ public class ListHashed implements LongFunction<List<Object>> {
"ListFunctions(NumberNameToString(),NumberNameToString())", "ListFunctions(NumberNameToString(),NumberNameToString())",
"Create a list of ['one','one']" "Create a list of ['one','one']"
}) })
public ListHashed(LongToIntFunction sizeFunc, LongUnaryOperator... funcs) { public ListHashed(LongUnaryOperator... funcs) {
List<LongFunction<?>> building = new ArrayList<>(funcs.length); List<LongFunction<?>> building = new ArrayList<>(funcs.length);
for (LongUnaryOperator func : funcs) { for (LongUnaryOperator func : funcs) {
building.add(func::applyAsLong); building.add(func::applyAsLong);
} }
this.sizeFunc = sizeFunc;
this.valueFuncs = building; this.valueFuncs = building;
this.size = building.size(); this.size = building.size();
} }
@ -61,12 +58,11 @@ public class ListHashed implements LongFunction<List<Object>> {
"ListFunctions(NumberNameToString(),NumberNameToString())", "ListFunctions(NumberNameToString(),NumberNameToString())",
"Create a list of ['one','one']" "Create a list of ['one','one']"
}) })
public ListHashed(LongToIntFunction sizeFunc, Function<Long,Object>... funcs) { public ListHashed(Function<Long,Object>... funcs) {
List<LongFunction<?>> building = new ArrayList<>(funcs.length); List<LongFunction<?>> building = new ArrayList<>(funcs.length);
for (Function<Long,Object> func : funcs) { for (Function<Long,Object> func : funcs) {
building.add(func::apply); building.add(func::apply);
} }
this.sizeFunc = sizeFunc;
this.valueFuncs = building; this.valueFuncs = building;
this.size = building.size(); this.size = building.size();
} }
@ -74,7 +70,6 @@ public class ListHashed implements LongFunction<List<Object>> {
@Override @Override
public List<Object> apply(long value) { public List<Object> apply(long value) {
long hash = value; long hash = value;
int size = sizeFunc.applyAsInt(value);
List<Object> list = new ArrayList<>(size); List<Object> list = new ArrayList<>(size);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
int selector = Math.min(i, valueFuncs.size() - 1); int selector = Math.min(i, valueFuncs.size() - 1);

View File

@ -28,7 +28,6 @@ import java.util.function.LongUnaryOperator;
public class ListSized implements LongFunction<List<Object>> { public class ListSized implements LongFunction<List<Object>> {
private final List<LongFunction<? extends Object>> valueFuncs; private final List<LongFunction<? extends Object>> valueFuncs;
private final int size;
private final LongToIntFunction sizeFunc; private final LongToIntFunction sizeFunc;
@Example({ @Example({
@ -38,7 +37,6 @@ public class ListSized implements LongFunction<List<Object>> {
public ListSized(LongToIntFunction sizeFunc, LongFunction<? extends Object>... funcs) { public ListSized(LongToIntFunction sizeFunc, LongFunction<? extends Object>... funcs) {
this.sizeFunc = sizeFunc; this.sizeFunc = sizeFunc;
this.valueFuncs = Arrays.asList(funcs); this.valueFuncs = Arrays.asList(funcs);
this.size = valueFuncs.size();
} }
@Example({ @Example({
@ -52,7 +50,6 @@ public class ListSized implements LongFunction<List<Object>> {
} }
this.sizeFunc = sizeFunc; this.sizeFunc = sizeFunc;
this.valueFuncs = building; this.valueFuncs = building;
this.size = building.size();
} }
@Example({ @Example({
@ -66,7 +63,6 @@ public class ListSized implements LongFunction<List<Object>> {
} }
this.sizeFunc = sizeFunc; this.sizeFunc = sizeFunc;
this.valueFuncs = building; this.valueFuncs = building;
this.size = building.size();
} }
@Override @Override

View File

@ -29,7 +29,6 @@ import java.util.function.LongUnaryOperator;
public class ListSizedHashed implements LongFunction<List<Object>> { public class ListSizedHashed implements LongFunction<List<Object>> {
private final List<LongFunction<? extends Object>> valueFuncs; private final List<LongFunction<? extends Object>> valueFuncs;
private final int size;
private final Hash hasher = new Hash(); private final Hash hasher = new Hash();
private final LongToIntFunction sizeFunc; private final LongToIntFunction sizeFunc;
@ -40,7 +39,6 @@ public class ListSizedHashed implements LongFunction<List<Object>> {
public ListSizedHashed(LongToIntFunction sizeFunc, LongFunction<? extends Object>... funcs) { public ListSizedHashed(LongToIntFunction sizeFunc, LongFunction<? extends Object>... funcs) {
this.sizeFunc = sizeFunc; this.sizeFunc = sizeFunc;
this.valueFuncs = Arrays.asList(funcs); this.valueFuncs = Arrays.asList(funcs);
this.size = valueFuncs.size();
} }
@Example({ @Example({
@ -54,7 +52,6 @@ public class ListSizedHashed implements LongFunction<List<Object>> {
} }
this.sizeFunc = sizeFunc; this.sizeFunc = sizeFunc;
this.valueFuncs = building; this.valueFuncs = building;
this.size = building.size();
} }
@Example({ @Example({
@ -68,7 +65,6 @@ public class ListSizedHashed implements LongFunction<List<Object>> {
} }
this.sizeFunc = sizeFunc; this.sizeFunc = sizeFunc;
this.valueFuncs = building; this.valueFuncs = building;
this.size = building.size();
} }
@Override @Override

View File

@ -29,7 +29,6 @@ import java.util.function.LongUnaryOperator;
public class ListSizedStepped implements LongFunction<List<Object>> { public class ListSizedStepped implements LongFunction<List<Object>> {
private final List<LongFunction<? extends Object>> valueFuncs; private final List<LongFunction<? extends Object>> valueFuncs;
private final int size;
private final LongToIntFunction sizeFunc; private final LongToIntFunction sizeFunc;
@Example({ @Example({
@ -39,7 +38,6 @@ public class ListSizedStepped implements LongFunction<List<Object>> {
public ListSizedStepped(LongToIntFunction sizeFunc, LongFunction<? extends Object>... funcs) { public ListSizedStepped(LongToIntFunction sizeFunc, LongFunction<? extends Object>... funcs) {
this.sizeFunc = sizeFunc; this.sizeFunc = sizeFunc;
this.valueFuncs = Arrays.asList(funcs); this.valueFuncs = Arrays.asList(funcs);
this.size = valueFuncs.size();
} }
@Example({ @Example({
@ -53,7 +51,6 @@ public class ListSizedStepped implements LongFunction<List<Object>> {
} }
this.sizeFunc = sizeFunc; this.sizeFunc = sizeFunc;
this.valueFuncs = building; this.valueFuncs = building;
this.size = building.size();
} }
@Example({ @Example({
@ -67,7 +64,6 @@ public class ListSizedStepped implements LongFunction<List<Object>> {
} }
this.sizeFunc = sizeFunc; this.sizeFunc = sizeFunc;
this.valueFuncs = building; this.valueFuncs = building;
this.size = building.size();
} }
@Override @Override

View File

@ -29,14 +29,12 @@ public class ListStepped implements LongFunction<List<Object>> {
private final List<LongFunction<? extends Object>> valueFuncs; private final List<LongFunction<? extends Object>> valueFuncs;
private final int size; private final int size;
private final LongToIntFunction sizeFunc;
@Example({ @Example({
"ListFunctions(NumberNameToString(),NumberNameToString())", "ListFunctions(NumberNameToString(),NumberNameToString())",
"Create a list of ['one','one']" "Create a list of ['one','one']"
}) })
public ListStepped(LongToIntFunction sizeFunc, LongFunction<? extends Object>... funcs) { public ListStepped(LongFunction<? extends Object>... funcs) {
this.sizeFunc = sizeFunc;
this.valueFuncs = Arrays.asList(funcs); this.valueFuncs = Arrays.asList(funcs);
this.size = valueFuncs.size(); this.size = valueFuncs.size();
} }
@ -45,12 +43,11 @@ public class ListStepped implements LongFunction<List<Object>> {
"ListFunctions(NumberNameToString(),NumberNameToString())", "ListFunctions(NumberNameToString(),NumberNameToString())",
"Create a list of ['one','one']" "Create a list of ['one','one']"
}) })
public ListStepped(LongToIntFunction sizeFunc, LongUnaryOperator... funcs) { public ListStepped(LongUnaryOperator... funcs) {
List<LongFunction<?>> building = new ArrayList<>(funcs.length); List<LongFunction<?>> building = new ArrayList<>(funcs.length);
for (LongUnaryOperator func : funcs) { for (LongUnaryOperator func : funcs) {
building.add(func::applyAsLong); building.add(func::applyAsLong);
} }
this.sizeFunc = sizeFunc;
this.valueFuncs = building; this.valueFuncs = building;
this.size = building.size(); this.size = building.size();
} }
@ -59,19 +56,17 @@ public class ListStepped implements LongFunction<List<Object>> {
"ListFunctions(NumberNameToString(),NumberNameToString())", "ListFunctions(NumberNameToString(),NumberNameToString())",
"Create a list of ['one','one']" "Create a list of ['one','one']"
}) })
public ListStepped(LongToIntFunction sizeFunc, Function<Long,Object>... funcs) { public ListStepped(Function<Long,Object>... funcs) {
List<LongFunction<?>> building = new ArrayList<>(funcs.length); List<LongFunction<?>> building = new ArrayList<>(funcs.length);
for (Function<Long,Object> func : funcs) { for (Function<Long,Object> func : funcs) {
building.add(func::apply); building.add(func::apply);
} }
this.sizeFunc = sizeFunc;
this.valueFuncs = building; this.valueFuncs = building;
this.size = building.size(); this.size = building.size();
} }
@Override @Override
public List<Object> apply(long value) { public List<Object> apply(long value) {
int size = sizeFunc.applyAsInt(value);
List<Object> list = new ArrayList<>(size); List<Object> list = new ArrayList<>(size);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
int selector = Math.min(i, valueFuncs.size() - 1); int selector = Math.min(i, valueFuncs.size() - 1);