diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Boolean2BooleanFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Boolean2BooleanFunction.java similarity index 96% rename from giraph-core/src/main/java/org/apache/giraph/function/primitive/Boolean2BooleanFunction.java rename to giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Boolean2BooleanFunction.java index afa8546a9..53c2e08d2 100644 --- a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Boolean2BooleanFunction.java +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Boolean2BooleanFunction.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.giraph.function.primitive; +package org.apache.giraph.function.primitive.func; import java.io.Serializable; diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Boolean2ByteFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Boolean2ByteFunction.java new file mode 100644 index 000000000..aed6de843 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Boolean2ByteFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (boolean) -> byte + */ +public interface Boolean2ByteFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + byte apply(boolean input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Boolean2DoubleFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Boolean2DoubleFunction.java new file mode 100644 index 000000000..206b52078 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Boolean2DoubleFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (boolean) -> double + */ +public interface Boolean2DoubleFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + double apply(boolean input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Boolean2FloatFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Boolean2FloatFunction.java new file mode 100644 index 000000000..6cd361f78 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Boolean2FloatFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (boolean) -> float + */ +public interface Boolean2FloatFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + float apply(boolean input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Boolean2IntFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Boolean2IntFunction.java new file mode 100644 index 000000000..1f19ccdb7 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Boolean2IntFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (boolean) -> int + */ +public interface Boolean2IntFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + int apply(boolean input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Boolean2LongFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Boolean2LongFunction.java new file mode 100644 index 000000000..ad089381d --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Boolean2LongFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (boolean) -> long + */ +public interface Boolean2LongFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + long apply(boolean input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Boolean2ShortFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Boolean2ShortFunction.java new file mode 100644 index 000000000..af68872aa --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Boolean2ShortFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (boolean) -> short + */ +public interface Boolean2ShortFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + short apply(boolean input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Byte2BooleanFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Byte2BooleanFunction.java new file mode 100644 index 000000000..f59dc547d --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Byte2BooleanFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (byte) -> boolean + */ +public interface Byte2BooleanFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + boolean apply(byte input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Byte2ByteFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Byte2ByteFunction.java similarity index 95% rename from giraph-core/src/main/java/org/apache/giraph/function/primitive/Byte2ByteFunction.java rename to giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Byte2ByteFunction.java index 38a279937..60f2bfc34 100644 --- a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Byte2ByteFunction.java +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Byte2ByteFunction.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.giraph.function.primitive; +package org.apache.giraph.function.primitive.func; import java.io.Serializable; diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Byte2DoubleFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Byte2DoubleFunction.java new file mode 100644 index 000000000..9cc9036d8 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Byte2DoubleFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (byte) -> double + */ +public interface Byte2DoubleFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + double apply(byte input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Byte2FloatFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Byte2FloatFunction.java new file mode 100644 index 000000000..d508dffb8 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Byte2FloatFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (byte) -> float + */ +public interface Byte2FloatFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + float apply(byte input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Byte2IntFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Byte2IntFunction.java new file mode 100644 index 000000000..0089fc2fc --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Byte2IntFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (byte) -> int + */ +public interface Byte2IntFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + int apply(byte input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Byte2LongFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Byte2LongFunction.java new file mode 100644 index 000000000..266aebb65 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Byte2LongFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (byte) -> long + */ +public interface Byte2LongFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + long apply(byte input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Byte2ShortFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Byte2ShortFunction.java new file mode 100644 index 000000000..608a759d8 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Byte2ShortFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (byte) -> short + */ +public interface Byte2ShortFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + short apply(byte input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Double2BooleanFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Double2BooleanFunction.java new file mode 100644 index 000000000..3706b6625 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Double2BooleanFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (double) -> boolean + */ +public interface Double2BooleanFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + boolean apply(double input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Double2ByteFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Double2ByteFunction.java new file mode 100644 index 000000000..faa78ab2a --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Double2ByteFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (double) -> byte + */ +public interface Double2ByteFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + byte apply(double input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Double2DoubleFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Double2DoubleFunction.java similarity index 96% rename from giraph-core/src/main/java/org/apache/giraph/function/primitive/Double2DoubleFunction.java rename to giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Double2DoubleFunction.java index 103117923..e67d20d15 100644 --- a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Double2DoubleFunction.java +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Double2DoubleFunction.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.giraph.function.primitive; +package org.apache.giraph.function.primitive.func; import java.io.Serializable; diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Double2FloatFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Double2FloatFunction.java new file mode 100644 index 000000000..d049c7508 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Double2FloatFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (double) -> float + */ +public interface Double2FloatFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + float apply(double input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Double2IntFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Double2IntFunction.java new file mode 100644 index 000000000..1b74c4d11 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Double2IntFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (double) -> int + */ +public interface Double2IntFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + int apply(double input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Double2LongFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Double2LongFunction.java new file mode 100644 index 000000000..3b3432afe --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Double2LongFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (double) -> long + */ +public interface Double2LongFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + long apply(double input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Double2ShortFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Double2ShortFunction.java new file mode 100644 index 000000000..65fef72ee --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Double2ShortFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (double) -> short + */ +public interface Double2ShortFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + short apply(double input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Float2BooleanFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Float2BooleanFunction.java new file mode 100644 index 000000000..b096b0f70 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Float2BooleanFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (float) -> boolean + */ +public interface Float2BooleanFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + boolean apply(float input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Float2ByteFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Float2ByteFunction.java new file mode 100644 index 000000000..e7bdec47d --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Float2ByteFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (float) -> byte + */ +public interface Float2ByteFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + byte apply(float input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Float2DoubleFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Float2DoubleFunction.java new file mode 100644 index 000000000..ec80ddac2 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Float2DoubleFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (float) -> double + */ +public interface Float2DoubleFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + double apply(float input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Float2FloatFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Float2FloatFunction.java similarity index 96% rename from giraph-core/src/main/java/org/apache/giraph/function/primitive/Float2FloatFunction.java rename to giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Float2FloatFunction.java index 2ccf585be..c5e5d2f9f 100644 --- a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Float2FloatFunction.java +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Float2FloatFunction.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.giraph.function.primitive; +package org.apache.giraph.function.primitive.func; import java.io.Serializable; diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Float2IntFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Float2IntFunction.java new file mode 100644 index 000000000..80e609d07 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Float2IntFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (float) -> int + */ +public interface Float2IntFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + int apply(float input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Float2LongFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Float2LongFunction.java new file mode 100644 index 000000000..a0ff4120e --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Float2LongFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (float) -> long + */ +public interface Float2LongFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + long apply(float input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Float2ShortFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Float2ShortFunction.java new file mode 100644 index 000000000..8887f047c --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Float2ShortFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (float) -> short + */ +public interface Float2ShortFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + short apply(float input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Int2BooleanFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Int2BooleanFunction.java new file mode 100644 index 000000000..09dd06637 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Int2BooleanFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (int) -> boolean + */ +public interface Int2BooleanFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + boolean apply(int input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Int2ByteFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Int2ByteFunction.java new file mode 100644 index 000000000..01db80fbf --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Int2ByteFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (int) -> byte + */ +public interface Int2ByteFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + byte apply(int input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Int2DoubleFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Int2DoubleFunction.java new file mode 100644 index 000000000..2f3b78fd3 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Int2DoubleFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (int) -> double + */ +public interface Int2DoubleFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + double apply(int input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Int2FloatFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Int2FloatFunction.java new file mode 100644 index 000000000..d911eebb2 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Int2FloatFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (int) -> float + */ +public interface Int2FloatFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + float apply(int input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Int2IntFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Int2IntFunction.java similarity index 95% rename from giraph-core/src/main/java/org/apache/giraph/function/primitive/Int2IntFunction.java rename to giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Int2IntFunction.java index e8c8cb9bc..6a93f99dc 100644 --- a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Int2IntFunction.java +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Int2IntFunction.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.giraph.function.primitive; +package org.apache.giraph.function.primitive.func; import java.io.Serializable; diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Int2LongFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Int2LongFunction.java new file mode 100644 index 000000000..dcef824f7 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Int2LongFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (int) -> long + */ +public interface Int2LongFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + long apply(int input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Int2ShortFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Int2ShortFunction.java new file mode 100644 index 000000000..8d2e973f3 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Int2ShortFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (int) -> short + */ +public interface Int2ShortFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + short apply(int input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Long2BooleanFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Long2BooleanFunction.java new file mode 100644 index 000000000..d34cc94bf --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Long2BooleanFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (long) -> boolean + */ +public interface Long2BooleanFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + boolean apply(long input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Long2ByteFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Long2ByteFunction.java new file mode 100644 index 000000000..0867a167e --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Long2ByteFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (long) -> byte + */ +public interface Long2ByteFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + byte apply(long input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Long2DoubleFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Long2DoubleFunction.java new file mode 100644 index 000000000..32ec807bf --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Long2DoubleFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (long) -> double + */ +public interface Long2DoubleFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + double apply(long input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Long2FloatFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Long2FloatFunction.java new file mode 100644 index 000000000..df984b299 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Long2FloatFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (long) -> float + */ +public interface Long2FloatFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + float apply(long input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Long2IntFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Long2IntFunction.java new file mode 100644 index 000000000..dca888a6a --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Long2IntFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (long) -> int + */ +public interface Long2IntFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + int apply(long input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Long2LongFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Long2LongFunction.java similarity index 95% rename from giraph-core/src/main/java/org/apache/giraph/function/primitive/Long2LongFunction.java rename to giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Long2LongFunction.java index 2f87cf57e..3032ed181 100644 --- a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Long2LongFunction.java +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Long2LongFunction.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.giraph.function.primitive; +package org.apache.giraph.function.primitive.func; import java.io.Serializable; diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Long2ShortFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Long2ShortFunction.java new file mode 100644 index 000000000..7dc6eec80 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Long2ShortFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (long) -> short + */ +public interface Long2ShortFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + short apply(long input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Short2BooleanFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Short2BooleanFunction.java new file mode 100644 index 000000000..cafca96dd --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Short2BooleanFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (short) -> boolean + */ +public interface Short2BooleanFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + boolean apply(short input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Short2ByteFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Short2ByteFunction.java new file mode 100644 index 000000000..8e5368b85 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Short2ByteFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (short) -> byte + */ +public interface Short2ByteFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + byte apply(short input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Short2DoubleFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Short2DoubleFunction.java new file mode 100644 index 000000000..4c65477ee --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Short2DoubleFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (short) -> double + */ +public interface Short2DoubleFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + double apply(short input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Short2FloatFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Short2FloatFunction.java new file mode 100644 index 000000000..e0fe4feed --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Short2FloatFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (short) -> float + */ +public interface Short2FloatFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + float apply(short input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Short2IntFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Short2IntFunction.java new file mode 100644 index 000000000..eb75d5362 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Short2IntFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (short) -> int + */ +public interface Short2IntFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + int apply(short input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Short2LongFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Short2LongFunction.java new file mode 100644 index 000000000..e3512e089 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Short2LongFunction.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.func; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (short) -> long + */ +public interface Short2LongFunction extends Serializable { + /** + * Returns the result of applying this function to given {@code input}. + * + * @param input input + * @return result + */ + long apply(short input); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Short2ShortFunction.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Short2ShortFunction.java similarity index 96% rename from giraph-core/src/main/java/org/apache/giraph/function/primitive/Short2ShortFunction.java rename to giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Short2ShortFunction.java index 53f627340..1b42fe9a8 100644 --- a/giraph-core/src/main/java/org/apache/giraph/function/primitive/Short2ShortFunction.java +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/Short2ShortFunction.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.giraph.function.primitive; +package org.apache.giraph.function.primitive.func; import java.io.Serializable; diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/package-info.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/package-info.java new file mode 100644 index 000000000..a03f2789a --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/func/package-info.java @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Primitive specializations of Function interface from + * org.apache.giraph.function package. + */ +package org.apache.giraph.function.primitive.func; diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/BooleanShortConsumer.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/BooleanShortConsumer.java new file mode 100644 index 000000000..b081319e5 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/BooleanShortConsumer.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (boolean, short) -> void + */ +public interface BooleanShortConsumer extends Serializable { + /** + * Applies this function to {@code input1} and {@code input2} + * + * @param input1 First input + * @param input2 Second input + */ + void apply(boolean input1, short input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/BooleanShortPredicate.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/BooleanShortPredicate.java new file mode 100644 index 000000000..09646e5c6 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/BooleanShortPredicate.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (boolean, short) -> boolean + */ +public interface BooleanShortPredicate extends Serializable { + /** + * Returns the result of applying this predicate to {@code input}. + * + * @param input1 First input + * @param input2 Second input + * @return result + */ + boolean apply(boolean input1, short input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ByteShortConsumer.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ByteShortConsumer.java new file mode 100644 index 000000000..0f08e2073 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ByteShortConsumer.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (byte, short) -> void + */ +public interface ByteShortConsumer extends Serializable { + /** + * Applies this function to {@code input1} and {@code input2} + * + * @param input1 First input + * @param input2 Second input + */ + void apply(byte input1, short input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ByteShortPredicate.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ByteShortPredicate.java new file mode 100644 index 000000000..c5307ccf5 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ByteShortPredicate.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (byte, short) -> boolean + */ +public interface ByteShortPredicate extends Serializable { + /** + * Returns the result of applying this predicate to {@code input}. + * + * @param input1 First input + * @param input2 Second input + * @return result + */ + boolean apply(byte input1, short input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/DoubleShortConsumer.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/DoubleShortConsumer.java new file mode 100644 index 000000000..f1aad929e --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/DoubleShortConsumer.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (double, short) -> void + */ +public interface DoubleShortConsumer extends Serializable { + /** + * Applies this function to {@code input1} and {@code input2} + * + * @param input1 First input + * @param input2 Second input + */ + void apply(double input1, short input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/DoubleShortPredicate.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/DoubleShortPredicate.java new file mode 100644 index 000000000..2ab43087e --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/DoubleShortPredicate.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (double, short) -> boolean + */ +public interface DoubleShortPredicate extends Serializable { + /** + * Returns the result of applying this predicate to {@code input}. + * + * @param input1 First input + * @param input2 Second input + * @return result + */ + boolean apply(double input1, short input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/FloatShortConsumer.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/FloatShortConsumer.java new file mode 100644 index 000000000..71817ffd2 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/FloatShortConsumer.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (float, short) -> void + */ +public interface FloatShortConsumer extends Serializable { + /** + * Applies this function to {@code input1} and {@code input2} + * + * @param input1 First input + * @param input2 Second input + */ + void apply(float input1, short input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/FloatShortPredicate.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/FloatShortPredicate.java new file mode 100644 index 000000000..c4bf0c8f1 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/FloatShortPredicate.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (float, short) -> boolean + */ +public interface FloatShortPredicate extends Serializable { + /** + * Returns the result of applying this predicate to {@code input}. + * + * @param input1 First input + * @param input2 Second input + * @return result + */ + boolean apply(float input1, short input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/IntShortConsumer.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/IntShortConsumer.java new file mode 100644 index 000000000..4cf4bd9c5 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/IntShortConsumer.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (int, short) -> void + */ +public interface IntShortConsumer extends Serializable { + /** + * Applies this function to {@code input1} and {@code input2} + * + * @param input1 First input + * @param input2 Second input + */ + void apply(int input1, short input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/IntShortPredicate.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/IntShortPredicate.java new file mode 100644 index 000000000..6633db274 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/IntShortPredicate.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (int, short) -> boolean + */ +public interface IntShortPredicate extends Serializable { + /** + * Returns the result of applying this predicate to {@code input}. + * + * @param input1 First input + * @param input2 Second input + * @return result + */ + boolean apply(int input1, short input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/LongShortConsumer.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/LongShortConsumer.java new file mode 100644 index 000000000..897cf7127 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/LongShortConsumer.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (long, short) -> void + */ +public interface LongShortConsumer extends Serializable { + /** + * Applies this function to {@code input1} and {@code input2} + * + * @param input1 First input + * @param input2 Second input + */ + void apply(long input1, short input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/LongShortPredicate.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/LongShortPredicate.java new file mode 100644 index 000000000..719fce490 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/LongShortPredicate.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (long, short) -> boolean + */ +public interface LongShortPredicate extends Serializable { + /** + * Returns the result of applying this predicate to {@code input}. + * + * @param input1 First input + * @param input2 Second input + * @return result + */ + boolean apply(long input1, short input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortBooleanConsumer.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortBooleanConsumer.java new file mode 100644 index 000000000..67a10b6e0 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortBooleanConsumer.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (short, boolean) -> void + */ +public interface ShortBooleanConsumer extends Serializable { + /** + * Applies this function to {@code input1} and {@code input2} + * + * @param input1 First input + * @param input2 Second input + */ + void apply(short input1, boolean input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortBooleanPredicate.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortBooleanPredicate.java new file mode 100644 index 000000000..7d3893239 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortBooleanPredicate.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (short, boolean) -> boolean + */ +public interface ShortBooleanPredicate extends Serializable { + /** + * Returns the result of applying this predicate to {@code input}. + * + * @param input1 First input + * @param input2 Second input + * @return result + */ + boolean apply(short input1, boolean input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortByteConsumer.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortByteConsumer.java new file mode 100644 index 000000000..414b5ec0b --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortByteConsumer.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (short, byte) -> void + */ +public interface ShortByteConsumer extends Serializable { + /** + * Applies this function to {@code input1} and {@code input2} + * + * @param input1 First input + * @param input2 Second input + */ + void apply(short input1, byte input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortBytePredicate.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortBytePredicate.java new file mode 100644 index 000000000..ea052fe53 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortBytePredicate.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (short, byte) -> boolean + */ +public interface ShortBytePredicate extends Serializable { + /** + * Returns the result of applying this predicate to {@code input}. + * + * @param input1 First input + * @param input2 Second input + * @return result + */ + boolean apply(short input1, byte input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortDoubleConsumer.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortDoubleConsumer.java new file mode 100644 index 000000000..38af93a55 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortDoubleConsumer.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (short, double) -> void + */ +public interface ShortDoubleConsumer extends Serializable { + /** + * Applies this function to {@code input1} and {@code input2} + * + * @param input1 First input + * @param input2 Second input + */ + void apply(short input1, double input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortDoublePredicate.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortDoublePredicate.java new file mode 100644 index 000000000..0405cb59b --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortDoublePredicate.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (short, double) -> boolean + */ +public interface ShortDoublePredicate extends Serializable { + /** + * Returns the result of applying this predicate to {@code input}. + * + * @param input1 First input + * @param input2 Second input + * @return result + */ + boolean apply(short input1, double input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortFloatConsumer.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortFloatConsumer.java new file mode 100644 index 000000000..a3a9716cc --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortFloatConsumer.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (short, float) -> void + */ +public interface ShortFloatConsumer extends Serializable { + /** + * Applies this function to {@code input1} and {@code input2} + * + * @param input1 First input + * @param input2 Second input + */ + void apply(short input1, float input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortFloatPredicate.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortFloatPredicate.java new file mode 100644 index 000000000..5994c261c --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortFloatPredicate.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (short, float) -> boolean + */ +public interface ShortFloatPredicate extends Serializable { + /** + * Returns the result of applying this predicate to {@code input}. + * + * @param input1 First input + * @param input2 Second input + * @return result + */ + boolean apply(short input1, float input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortIntConsumer.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortIntConsumer.java new file mode 100644 index 000000000..3eaa4a4b8 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortIntConsumer.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (short, int) -> void + */ +public interface ShortIntConsumer extends Serializable { + /** + * Applies this function to {@code input1} and {@code input2} + * + * @param input1 First input + * @param input2 Second input + */ + void apply(short input1, int input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortIntPredicate.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortIntPredicate.java new file mode 100644 index 000000000..e074c4553 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortIntPredicate.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (short, int) -> boolean + */ +public interface ShortIntPredicate extends Serializable { + /** + * Returns the result of applying this predicate to {@code input}. + * + * @param input1 First input + * @param input2 Second input + * @return result + */ + boolean apply(short input1, int input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortLongConsumer.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortLongConsumer.java new file mode 100644 index 000000000..2b37e4eaa --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortLongConsumer.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (short, long) -> void + */ +public interface ShortLongConsumer extends Serializable { + /** + * Applies this function to {@code input1} and {@code input2} + * + * @param input1 First input + * @param input2 Second input + */ + void apply(short input1, long input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortLongPredicate.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortLongPredicate.java new file mode 100644 index 000000000..dc18e62a0 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortLongPredicate.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (short, long) -> boolean + */ +public interface ShortLongPredicate extends Serializable { + /** + * Returns the result of applying this predicate to {@code input}. + * + * @param input1 First input + * @param input2 Second input + * @return result + */ + boolean apply(short input1, long input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortShortConsumer.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortShortConsumer.java new file mode 100644 index 000000000..2f51848ac --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortShortConsumer.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (short, short) -> void + */ +public interface ShortShortConsumer extends Serializable { + /** + * Applies this function to {@code input1} and {@code input2} + * + * @param input1 First input + * @param input2 Second input + */ + void apply(short input1, short input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortShortPredicate.java b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortShortPredicate.java new file mode 100644 index 000000000..921bc9f72 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/function/primitive/pairs/ShortShortPredicate.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.function.primitive.pairs; + +import java.io.Serializable; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Primitive specialization of Function: + * (short, short) -> boolean + */ +public interface ShortShortPredicate extends Serializable { + /** + * Returns the result of applying this predicate to {@code input}. + * + * @param input1 First input + * @param input2 Second input + * @return result + */ + boolean apply(short input1, short input2); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntShortMinHeap.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntShortMinHeap.java new file mode 100644 index 000000000..2ec33bfff --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityIntShortMinHeap.java @@ -0,0 +1,361 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.giraph.types.heaps; + +import it.unimi.dsi.fastutil.ints.AbstractInt2ShortMap; +import it.unimi.dsi.fastutil.ints.Int2ShortMap; +import it.unimi.dsi.fastutil.objects.ObjectIterator; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.NoSuchElementException; + +import org.apache.giraph.function.primitive.pairs.IntShortConsumer; +import org.apache.giraph.function.primitive.pairs.IntShortPredicate; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Min heap which holds (int key, short value) pairs with + * the largest values as its elements, up to the given maximum number of + * elements. + * + * When multiple elements with same values are added and there is no space for + * all of them in the heap, the one with larger keys will be kept in the heap. + * + * You can remove a pair with the minimum value currently in the heap. + */ +public class FixedCapacityIntShortMinHeap + implements Int2ShortMapEntryIterable { + /** Keys in the heap */ + private final int[] keys; + /** Values in the heap */ + private final short[] values; + /** Number of elements currently in the heap */ + private int size; + /** Capacity of the heap */ + private final int capacity; + /** Reusable iterator instance */ + private final IteratorImpl iterator; + + /** + * Initialize the heap with desired capacity + * + * @param capacity Capacity + */ + public FixedCapacityIntShortMinHeap(int capacity) { + keys = new int[capacity]; + values = new short[capacity]; + size = 0; + this.capacity = capacity; + iterator = new IteratorImpl(); + } + + /** Clear the heap */ + public void clear() { + size = 0; + } + + /** + * Add a key value pair + * + * @param key Key + * @param value Value + */ + public void add(int key, short value) { + if (size == capacity && compare(keys[0], values[0], key, value) >= 0) { + // If the heap is full and smallest element in it is not smaller + // than value, do nothing + return; + } + int position; + if (size < capacity) { + // If the heap is not full, increase its size and find the position for + // new element (up-heap search) + position = size; + size++; + while (position > 0) { + int parent = (position - 1) >> 1; + if (compare(keys[parent], values[parent], key, value) < 0) { + break; + } + values[position] = values[parent]; + keys[position] = keys[parent]; + position = parent; + } + } else { + // If the heap is full, remove element from the root and find the position + // for new element (down-heap search) + position = removeRootAndFindPosition(key, value); + } + // Fill position with key value pair + keys[position] = key; + values[position] = value; + } + + /** + * @return Key corresponding to the minimum value currently in the heap + * @throws NoSuchElementException if the heap is empty. + */ + public int getMinKey() { + if (size() > 0) { + return keys[0]; + } else { + throw new NoSuchElementException(); + } + } + + /** + * @return Minimum value currently in the heap + * @throws NoSuchElementException if the heap is empty. + */ + public short getMinValue() { + if (size() > 0) { + return values[0]; + } else { + throw new NoSuchElementException(); + } + } + + /** + * Removes the (key, value) pair that corresponds to the minimum value + * currently in the heap. + */ + public void removeMin() { + if (size() > 0) { + size--; + int position = removeRootAndFindPosition(keys[size], values[size]); + keys[position] = keys[size]; + values[position] = values[size]; + } + } + + /** + * Comapre two (key, value) entries + * + * @param key1 First key + * @param value1 First value + * @param key2 Second key + * @param value2 Second value + * @return 0 if entries are equal, < 0 if first entry is smaller than the + * second one, and > 0 if first entry is larger than the second one + */ + protected int compare(int key1, short value1, + int key2, short value2) { + int t = Short.compare(value1, value2); + return (t == 0) ? Integer.compare(key1, key2) : t; + } + + @Override + public ObjectIterator iterator() { + iterator.reset(); + return iterator; + } + + @Override + public int size() { + return size; + } + + /** + * Check if the heap is empty + * + * @return True iff the heap is empty + */ + public boolean isEmpty() { + return size == 0; + } + + /** + * Get capacity of the heap + * + * @return Heap capacity + */ + public int getCapacity() { + return capacity; + } + + /** + * Serializes an object into data output. + * + * @param heap Object instance to serialize + * @param out Data output + * @throws java.io.IOException + */ + public static void write(FixedCapacityIntShortMinHeap heap, + DataOutput out) throws IOException { + out.writeInt(heap.capacity); + out.writeInt(heap.size); + for (int i = 0; i < heap.size(); i++) { + out.writeInt(heap.keys[i]); + out.writeShort(heap.values[i]); + } + } + + /** + * Deserializes an object from data input. + * + * @param heap Object to reuse if possible + * @param in Data input + * @return FixedCapacityIntShortMinHeap deserialized from data input. + * @throws IOException + */ + public static FixedCapacityIntShortMinHeap read( + FixedCapacityIntShortMinHeap heap, DataInput in) + throws IOException { + int capacity = in.readInt(); + if (heap == null || heap.capacity != capacity) { + heap = new FixedCapacityIntShortMinHeap(capacity); + } else { + heap.clear(); + } + heap.size = in.readInt(); + for (int i = 0; i < heap.size; i++) { + heap.keys[i] = in.readInt(); + heap.values[i] = in.readShort(); + } + return heap; + } + + /** + * Takes a (key, value) pair, removes the root of the heap, and finds + * a position where the pair can be inserted. + * + * @param key Key + * @param value Value + * @return Position in the heap where the (key, value) pair can be inserted + * while preserving the heap property. + */ + private int removeRootAndFindPosition(int key, short value) { + int position = 0; + while (position < size) { + // Find the left child + int minChild = (position << 1) + 1; + // Compare the left and the right child values - find the smaller one + if (minChild + 1 < size && + compare(keys[minChild + 1], values[minChild + 1], + keys[minChild], values[minChild]) < 0) { + minChild++; + } + if (minChild >= size || compare(keys[minChild], values[minChild], + key, value) >= 0) { + break; + } + keys[position] = keys[minChild]; + values[position] = values[minChild]; + position = minChild; + } + return position; + } + + /** + * Traverse all elements of the heap, calling given function on each element. + * + * @param f Function to call on each element. + */ + public void forEachIntShort(IntShortConsumer f) { + for (int i = 0; i < size(); ++i) { + f.apply(keys[i], values[i]); + } + } + + /** + * Traverse all elements of the heap, calling given function on each element, + * or until predicate returns false. + * + * @param f Function to call on each element. + * @return true if the predicate returned true for all elements, + * false if it returned false for some element. + */ + public boolean forEachWhileIntShort(IntShortPredicate f) { + for (int i = 0; i < size(); ++i) { + if (!f.apply(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** Iterator for FixedCapacityIntShortMinHeap */ + private class IteratorImpl implements ObjectIterator { + /** Reusable entry */ + private final MutableEntry entry = new MutableEntry(); + /** Current index */ + private int index; + + /** Reset the iterator so it can be reused */ + public void reset() { + index = -1; + } + + @Override + public boolean hasNext() { + return index < size - 1; + } + + @Override + public Int2ShortMap.Entry next() { + if (!hasNext()) { + throw new NoSuchElementException(); + } + index++; + entry.setIntKey(keys[index]); + entry.setShortValue(values[index]); + return entry; + } + + @Override + public void remove() { + throw new UnsupportedOperationException("remove() shouldn't be called"); + } + + @Override + public int skip(int i) { + throw new UnsupportedOperationException("skip(int) shouldn't be called"); + } + } + + /** Helper mutable Entry class */ + private static class MutableEntry extends AbstractInt2ShortMap.BasicEntry { + /** Default constructor */ + private MutableEntry() { + super(0, (short) 0); + } + + /** + * Set key + * + * @param key Key to set + */ + private void setIntKey(int key) { + this.key = key; + } + + /** + * Set value + * + * @param value Value to set + */ + private void setShortValue(short value) { + this.value = value; + } + } +} diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongShortMinHeap.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongShortMinHeap.java new file mode 100644 index 000000000..cd0cd4c5a --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/FixedCapacityLongShortMinHeap.java @@ -0,0 +1,361 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.giraph.types.heaps; + +import it.unimi.dsi.fastutil.longs.AbstractLong2ShortMap; +import it.unimi.dsi.fastutil.longs.Long2ShortMap; +import it.unimi.dsi.fastutil.objects.ObjectIterator; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.NoSuchElementException; + +import org.apache.giraph.function.primitive.pairs.LongShortConsumer; +import org.apache.giraph.function.primitive.pairs.LongShortPredicate; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Min heap which holds (long key, short value) pairs with + * the largest values as its elements, up to the given maximum number of + * elements. + * + * When multiple elements with same values are added and there is no space for + * all of them in the heap, the one with larger keys will be kept in the heap. + * + * You can remove a pair with the minimum value currently in the heap. + */ +public class FixedCapacityLongShortMinHeap + implements Long2ShortMapEntryIterable { + /** Keys in the heap */ + private final long[] keys; + /** Values in the heap */ + private final short[] values; + /** Number of elements currently in the heap */ + private int size; + /** Capacity of the heap */ + private final int capacity; + /** Reusable iterator instance */ + private final IteratorImpl iterator; + + /** + * Initialize the heap with desired capacity + * + * @param capacity Capacity + */ + public FixedCapacityLongShortMinHeap(int capacity) { + keys = new long[capacity]; + values = new short[capacity]; + size = 0; + this.capacity = capacity; + iterator = new IteratorImpl(); + } + + /** Clear the heap */ + public void clear() { + size = 0; + } + + /** + * Add a key value pair + * + * @param key Key + * @param value Value + */ + public void add(long key, short value) { + if (size == capacity && compare(keys[0], values[0], key, value) >= 0) { + // If the heap is full and smallest element in it is not smaller + // than value, do nothing + return; + } + int position; + if (size < capacity) { + // If the heap is not full, increase its size and find the position for + // new element (up-heap search) + position = size; + size++; + while (position > 0) { + int parent = (position - 1) >> 1; + if (compare(keys[parent], values[parent], key, value) < 0) { + break; + } + values[position] = values[parent]; + keys[position] = keys[parent]; + position = parent; + } + } else { + // If the heap is full, remove element from the root and find the position + // for new element (down-heap search) + position = removeRootAndFindPosition(key, value); + } + // Fill position with key value pair + keys[position] = key; + values[position] = value; + } + + /** + * @return Key corresponding to the minimum value currently in the heap + * @throws NoSuchElementException if the heap is empty. + */ + public long getMinKey() { + if (size() > 0) { + return keys[0]; + } else { + throw new NoSuchElementException(); + } + } + + /** + * @return Minimum value currently in the heap + * @throws NoSuchElementException if the heap is empty. + */ + public short getMinValue() { + if (size() > 0) { + return values[0]; + } else { + throw new NoSuchElementException(); + } + } + + /** + * Removes the (key, value) pair that corresponds to the minimum value + * currently in the heap. + */ + public void removeMin() { + if (size() > 0) { + size--; + int position = removeRootAndFindPosition(keys[size], values[size]); + keys[position] = keys[size]; + values[position] = values[size]; + } + } + + /** + * Comapre two (key, value) entries + * + * @param key1 First key + * @param value1 First value + * @param key2 Second key + * @param value2 Second value + * @return 0 if entries are equal, < 0 if first entry is smaller than the + * second one, and > 0 if first entry is larger than the second one + */ + protected int compare(long key1, short value1, + long key2, short value2) { + int t = Short.compare(value1, value2); + return (t == 0) ? Long.compare(key1, key2) : t; + } + + @Override + public ObjectIterator iterator() { + iterator.reset(); + return iterator; + } + + @Override + public int size() { + return size; + } + + /** + * Check if the heap is empty + * + * @return True iff the heap is empty + */ + public boolean isEmpty() { + return size == 0; + } + + /** + * Get capacity of the heap + * + * @return Heap capacity + */ + public int getCapacity() { + return capacity; + } + + /** + * Serializes an object into data output. + * + * @param heap Object instance to serialize + * @param out Data output + * @throws java.io.IOException + */ + public static void write(FixedCapacityLongShortMinHeap heap, + DataOutput out) throws IOException { + out.writeInt(heap.capacity); + out.writeInt(heap.size); + for (int i = 0; i < heap.size(); i++) { + out.writeLong(heap.keys[i]); + out.writeShort(heap.values[i]); + } + } + + /** + * Deserializes an object from data input. + * + * @param heap Object to reuse if possible + * @param in Data input + * @return FixedCapacityLongShortMinHeap deserialized from data input. + * @throws IOException + */ + public static FixedCapacityLongShortMinHeap read( + FixedCapacityLongShortMinHeap heap, DataInput in) + throws IOException { + int capacity = in.readInt(); + if (heap == null || heap.capacity != capacity) { + heap = new FixedCapacityLongShortMinHeap(capacity); + } else { + heap.clear(); + } + heap.size = in.readInt(); + for (int i = 0; i < heap.size; i++) { + heap.keys[i] = in.readLong(); + heap.values[i] = in.readShort(); + } + return heap; + } + + /** + * Takes a (key, value) pair, removes the root of the heap, and finds + * a position where the pair can be inserted. + * + * @param key Key + * @param value Value + * @return Position in the heap where the (key, value) pair can be inserted + * while preserving the heap property. + */ + private int removeRootAndFindPosition(long key, short value) { + int position = 0; + while (position < size) { + // Find the left child + int minChild = (position << 1) + 1; + // Compare the left and the right child values - find the smaller one + if (minChild + 1 < size && + compare(keys[minChild + 1], values[minChild + 1], + keys[minChild], values[minChild]) < 0) { + minChild++; + } + if (minChild >= size || compare(keys[minChild], values[minChild], + key, value) >= 0) { + break; + } + keys[position] = keys[minChild]; + values[position] = values[minChild]; + position = minChild; + } + return position; + } + + /** + * Traverse all elements of the heap, calling given function on each element. + * + * @param f Function to call on each element. + */ + public void forEachLongShort(LongShortConsumer f) { + for (int i = 0; i < size(); ++i) { + f.apply(keys[i], values[i]); + } + } + + /** + * Traverse all elements of the heap, calling given function on each element, + * or until predicate returns false. + * + * @param f Function to call on each element. + * @return true if the predicate returned true for all elements, + * false if it returned false for some element. + */ + public boolean forEachWhileLongShort(LongShortPredicate f) { + for (int i = 0; i < size(); ++i) { + if (!f.apply(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** Iterator for FixedCapacityLongShortMinHeap */ + private class IteratorImpl implements ObjectIterator { + /** Reusable entry */ + private final MutableEntry entry = new MutableEntry(); + /** Current index */ + private int index; + + /** Reset the iterator so it can be reused */ + public void reset() { + index = -1; + } + + @Override + public boolean hasNext() { + return index < size - 1; + } + + @Override + public Long2ShortMap.Entry next() { + if (!hasNext()) { + throw new NoSuchElementException(); + } + index++; + entry.setLongKey(keys[index]); + entry.setShortValue(values[index]); + return entry; + } + + @Override + public void remove() { + throw new UnsupportedOperationException("remove() shouldn't be called"); + } + + @Override + public int skip(int i) { + throw new UnsupportedOperationException("skip(int) shouldn't be called"); + } + } + + /** Helper mutable Entry class */ + private static class MutableEntry extends AbstractLong2ShortMap.BasicEntry { + /** Default constructor */ + private MutableEntry() { + super(0, (short) 0); + } + + /** + * Set key + * + * @param key Key to set + */ + private void setLongKey(long key) { + this.key = key; + } + + /** + * Set value + * + * @param value Value to set + */ + private void setShortValue(short value) { + this.value = value; + } + } +} diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2ByteMapEntryIterable.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2ByteMapEntryIterable.java index bac1ab55c..890619fc2 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2ByteMapEntryIterable.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2ByteMapEntryIterable.java @@ -18,7 +18,7 @@ package org.apache.giraph.types.heaps; -import it.unimi.dsi.fastutil.ints.Int2ByteMap;; +import it.unimi.dsi.fastutil.ints.Int2ByteMap; import it.unimi.dsi.fastutil.objects.ObjectIterable; import it.unimi.dsi.fastutil.objects.ObjectIterator; diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2DoubleMapEntryIterable.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2DoubleMapEntryIterable.java index 8776c3eb4..c1e3cac28 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2DoubleMapEntryIterable.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2DoubleMapEntryIterable.java @@ -18,7 +18,7 @@ package org.apache.giraph.types.heaps; -import it.unimi.dsi.fastutil.ints.Int2DoubleMap;; +import it.unimi.dsi.fastutil.ints.Int2DoubleMap; import it.unimi.dsi.fastutil.objects.ObjectIterable; import it.unimi.dsi.fastutil.objects.ObjectIterator; diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2FloatMapEntryIterable.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2FloatMapEntryIterable.java index 09111f5d0..75bd4ccdb 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2FloatMapEntryIterable.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2FloatMapEntryIterable.java @@ -18,7 +18,7 @@ package org.apache.giraph.types.heaps; -import it.unimi.dsi.fastutil.ints.Int2FloatMap;; +import it.unimi.dsi.fastutil.ints.Int2FloatMap; import it.unimi.dsi.fastutil.objects.ObjectIterable; import it.unimi.dsi.fastutil.objects.ObjectIterator; diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2IntMapEntryIterable.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2IntMapEntryIterable.java index 7d48705e4..7e1921442 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2IntMapEntryIterable.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2IntMapEntryIterable.java @@ -18,7 +18,7 @@ package org.apache.giraph.types.heaps; -import it.unimi.dsi.fastutil.ints.Int2IntMap;; +import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.objects.ObjectIterable; import it.unimi.dsi.fastutil.objects.ObjectIterator; diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2LongMapEntryIterable.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2LongMapEntryIterable.java index b4e5c8c9c..3b88160d0 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2LongMapEntryIterable.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2LongMapEntryIterable.java @@ -18,7 +18,7 @@ package org.apache.giraph.types.heaps; -import it.unimi.dsi.fastutil.ints.Int2LongMap;; +import it.unimi.dsi.fastutil.ints.Int2LongMap; import it.unimi.dsi.fastutil.objects.ObjectIterable; import it.unimi.dsi.fastutil.objects.ObjectIterator; diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2ShortMapEntryIterable.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2ShortMapEntryIterable.java new file mode 100644 index 000000000..186699266 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Int2ShortMapEntryIterable.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.giraph.types.heaps; + +import it.unimi.dsi.fastutil.ints.Int2ShortMap; +import it.unimi.dsi.fastutil.objects.ObjectIterable; +import it.unimi.dsi.fastutil.objects.ObjectIterator; + +/** + * Iterable which has its size and + * ObjectIterator<Int2ShortMap.Entry> + */ +public interface Int2ShortMapEntryIterable + extends ObjectIterable { + /** + * Get the iterator. Not thread-safe and reuses iterator object, + * so you can't have several iterators at the same time. + * + * @return Iterator + */ + ObjectIterator iterator(); + + /** + * Get the size of this iterable + * + * @return Size + */ + int size(); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2ByteMapEntryIterable.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2ByteMapEntryIterable.java index 4c27d7838..4cdb4431e 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2ByteMapEntryIterable.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2ByteMapEntryIterable.java @@ -18,7 +18,7 @@ package org.apache.giraph.types.heaps; -import it.unimi.dsi.fastutil.longs.Long2ByteMap;; +import it.unimi.dsi.fastutil.longs.Long2ByteMap; import it.unimi.dsi.fastutil.objects.ObjectIterable; import it.unimi.dsi.fastutil.objects.ObjectIterator; diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2DoubleMapEntryIterable.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2DoubleMapEntryIterable.java index 8b7cb1761..eae3e6a32 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2DoubleMapEntryIterable.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2DoubleMapEntryIterable.java @@ -18,7 +18,7 @@ package org.apache.giraph.types.heaps; -import it.unimi.dsi.fastutil.longs.Long2DoubleMap;; +import it.unimi.dsi.fastutil.longs.Long2DoubleMap; import it.unimi.dsi.fastutil.objects.ObjectIterable; import it.unimi.dsi.fastutil.objects.ObjectIterator; diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2FloatMapEntryIterable.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2FloatMapEntryIterable.java index 802f54c15..908efcfc3 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2FloatMapEntryIterable.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2FloatMapEntryIterable.java @@ -18,7 +18,7 @@ package org.apache.giraph.types.heaps; -import it.unimi.dsi.fastutil.longs.Long2FloatMap;; +import it.unimi.dsi.fastutil.longs.Long2FloatMap; import it.unimi.dsi.fastutil.objects.ObjectIterable; import it.unimi.dsi.fastutil.objects.ObjectIterator; diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2IntMapEntryIterable.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2IntMapEntryIterable.java index da99c7156..8cc336eae 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2IntMapEntryIterable.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2IntMapEntryIterable.java @@ -18,7 +18,7 @@ package org.apache.giraph.types.heaps; -import it.unimi.dsi.fastutil.longs.Long2IntMap;; +import it.unimi.dsi.fastutil.longs.Long2IntMap; import it.unimi.dsi.fastutil.objects.ObjectIterable; import it.unimi.dsi.fastutil.objects.ObjectIterator; diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2LongMapEntryIterable.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2LongMapEntryIterable.java index e1e78a176..2fc319b3a 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2LongMapEntryIterable.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2LongMapEntryIterable.java @@ -18,7 +18,7 @@ package org.apache.giraph.types.heaps; -import it.unimi.dsi.fastutil.longs.Long2LongMap;; +import it.unimi.dsi.fastutil.longs.Long2LongMap; import it.unimi.dsi.fastutil.objects.ObjectIterable; import it.unimi.dsi.fastutil.objects.ObjectIterator; diff --git a/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2ShortMapEntryIterable.java b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2ShortMapEntryIterable.java new file mode 100644 index 000000000..e30e23145 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/types/heaps/Long2ShortMapEntryIterable.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.giraph.types.heaps; + +import it.unimi.dsi.fastutil.longs.Long2ShortMap; +import it.unimi.dsi.fastutil.objects.ObjectIterable; +import it.unimi.dsi.fastutil.objects.ObjectIterator; + +/** + * Iterable which has its size and + * ObjectIterator<Long2ShortMap.Entry> + */ +public interface Long2ShortMapEntryIterable + extends ObjectIterable { + /** + * Get the iterator. Not thread-safe and reuses iterator object, + * so you can't have several iterators at the same time. + * + * @return Iterator + */ + ObjectIterator iterator(); + + /** + * Get the size of this iterable + * + * @return Size + */ + int size(); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/ByteTypeOps.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/ByteTypeOps.java index 71a30dace..5997cc7b5 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/ops/ByteTypeOps.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/ByteTypeOps.java @@ -18,6 +18,9 @@ package org.apache.giraph.types.ops; import org.apache.giraph.types.ops.collections.array.WByteArrayList; +import org.apache.giraph.types.ops.collections.map.BasicByte2ObjectOpenHashMap; +import org.apache.giraph.types.ops.collections.set.BasicByteOpenHashSet; +import org.apache.giraph.types.ops.collections.WritableWriter; import org.apache.hadoop.io.ByteWritable; import java.io.DataInput; @@ -28,7 +31,7 @@ /** TypeOps implementation for working with ByteWritable type */ public enum ByteTypeOps implements - PrimitiveTypeOps, NumericTypeOps { + PrimitiveIdTypeOps, NumericTypeOps { /** Singleton instance */ INSTANCE; @@ -67,6 +70,28 @@ public WByteArrayList readNewArrayList(DataInput in) throws IOException { return WByteArrayList.readNew(in); } + @Override + public BasicByteOpenHashSet createOpenHashSet() { + return new BasicByteOpenHashSet(); + } + + @Override + public BasicByteOpenHashSet createOpenHashSet(long capacity) { + return new BasicByteOpenHashSet((int) capacity); + } + + @Override + public BasicByte2ObjectOpenHashMap create2ObjectOpenHashMap( + WritableWriter valueWriter) { + return new BasicByte2ObjectOpenHashMap<>(valueWriter); + } + + @Override + public BasicByte2ObjectOpenHashMap create2ObjectOpenHashMap( + int capacity, WritableWriter valueWriter) { + return new BasicByte2ObjectOpenHashMap<>(capacity, valueWriter); + } + @Override public ByteWritable createZero() { return new ByteWritable((byte) 0); diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/IntTypeOps.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/IntTypeOps.java index a03cf94bb..dda166486 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/ops/IntTypeOps.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/IntTypeOps.java @@ -17,9 +17,9 @@ */ package org.apache.giraph.types.ops; -import org.apache.giraph.types.ops.collections.Basic2ObjectMap.BasicInt2ObjectOpenHashMap; -import org.apache.giraph.types.ops.collections.BasicSet.BasicIntOpenHashSet; import org.apache.giraph.types.ops.collections.array.WIntArrayList; +import org.apache.giraph.types.ops.collections.map.BasicInt2ObjectOpenHashMap; +import org.apache.giraph.types.ops.collections.set.BasicIntOpenHashSet; import org.apache.giraph.types.ops.collections.WritableWriter; import org.apache.hadoop.io.IntWritable; diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/LongTypeOps.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/LongTypeOps.java index 916d166bc..bacf5eefa 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/ops/LongTypeOps.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/LongTypeOps.java @@ -17,9 +17,9 @@ */ package org.apache.giraph.types.ops; -import org.apache.giraph.types.ops.collections.Basic2ObjectMap.BasicLong2ObjectOpenHashMap; -import org.apache.giraph.types.ops.collections.BasicSet.BasicLongOpenHashSet; import org.apache.giraph.types.ops.collections.array.WLongArrayList; +import org.apache.giraph.types.ops.collections.map.BasicLong2ObjectOpenHashMap; +import org.apache.giraph.types.ops.collections.set.BasicLongOpenHashSet; import org.apache.giraph.types.ops.collections.WritableWriter; import org.apache.hadoop.io.LongWritable; diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/ShortTypeOps.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/ShortTypeOps.java new file mode 100644 index 000000000..80f86ecb3 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/ShortTypeOps.java @@ -0,0 +1,134 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.types.ops; + +import org.apache.giraph.types.ops.collections.array.WShortArrayList; +import org.apache.giraph.types.ops.collections.map.BasicShort2ObjectOpenHashMap; +import org.apache.giraph.types.ops.collections.set.BasicShortOpenHashSet; +import org.apache.giraph.types.ops.collections.WritableWriter; +import org.apache.hadoop.io.ShortWritable; + +import java.io.DataInput; +import java.io.IOException; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** TypeOps implementation for working with ShortWritable type */ +public enum ShortTypeOps implements + PrimitiveIdTypeOps, NumericTypeOps { + /** Singleton instance */ + INSTANCE; + + @Override + public Class getTypeClass() { + return ShortWritable.class; + } + + @Override + public ShortWritable create() { + return new ShortWritable(); + } + + @Override + public ShortWritable createCopy(ShortWritable from) { + return new ShortWritable(from.get()); + } + + @Override + public void set(ShortWritable to, ShortWritable from) { + to.set(from.get()); + } + + @Override + public WShortArrayList createArrayList() { + return new WShortArrayList(); + } + + @Override + public WShortArrayList createArrayList(int capacity) { + return new WShortArrayList(capacity); + } + + @Override + public WShortArrayList readNewArrayList(DataInput in) throws IOException { + return WShortArrayList.readNew(in); + } + + @Override + public BasicShortOpenHashSet createOpenHashSet() { + return new BasicShortOpenHashSet(); + } + + @Override + public BasicShortOpenHashSet createOpenHashSet(long capacity) { + return new BasicShortOpenHashSet((int) capacity); + } + + @Override + public BasicShort2ObjectOpenHashMap create2ObjectOpenHashMap( + WritableWriter valueWriter) { + return new BasicShort2ObjectOpenHashMap<>(valueWriter); + } + + @Override + public BasicShort2ObjectOpenHashMap create2ObjectOpenHashMap( + int capacity, WritableWriter valueWriter) { + return new BasicShort2ObjectOpenHashMap<>(capacity, valueWriter); + } + + @Override + public ShortWritable createZero() { + return new ShortWritable((short) 0); + } + + @Override + public ShortWritable createOne() { + return new ShortWritable((short) 1); + } + + @Override + public ShortWritable createMinNegativeValue() { + return new ShortWritable(Short.MIN_VALUE); + } + + @Override + public ShortWritable createMaxPositiveValue() { + return new ShortWritable(Short.MAX_VALUE); + } + + @Override + public void plusInto(ShortWritable value, ShortWritable increment) { + value.set((short) (value.get() + increment.get())); + } + + @Override + public void multiplyInto(ShortWritable value, ShortWritable multiplier) { + value.set((short) (value.get() * multiplier.get())); + } + + @Override + public void negate(ShortWritable value) { + value.set((short) (-value.get())); + } + + @Override + public int compare(ShortWritable value1, ShortWritable value2) { + return Short.compare(value1.get(), value2.get()); + } +} diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/Basic2ObjectMap.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/Basic2ObjectMap.java index 8f0029396..146202033 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/Basic2ObjectMap.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/Basic2ObjectMap.java @@ -17,32 +17,22 @@ */ package org.apache.giraph.types.ops.collections; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -import it.unimi.dsi.fastutil.ints.IntIterator; -import it.unimi.dsi.fastutil.longs.Long2ObjectMap; -import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; -import it.unimi.dsi.fastutil.longs.LongIterator; -import it.unimi.dsi.fastutil.objects.Object2ObjectMap; -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; -import it.unimi.dsi.fastutil.objects.ObjectIterator; - import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; import java.util.Collection; import java.util.Iterator; -import org.apache.giraph.types.ops.IntTypeOps; -import org.apache.giraph.types.ops.LongTypeOps; import org.apache.giraph.types.ops.PrimitiveIdTypeOps; import org.apache.giraph.utils.WritableUtils; -import org.apache.hadoop.io.IntWritable; -import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Writable; import com.google.common.base.Preconditions; +import it.unimi.dsi.fastutil.objects.Object2ObjectMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.objects.ObjectIterator; + /** * Basic2ObjectMap with only basic set of operations. * All operations that return object K are returning reusable object, @@ -122,7 +112,7 @@ public abstract class Basic2ObjectMap implements Writable { * * @param Primitive key iterator type */ - protected abstract class ReusableIterator> + public abstract class ReusableIterator> implements ResettableIterator { /** Primitive Key iterator */ protected Iter iter; @@ -148,249 +138,6 @@ public void remove() { } } - /** IntWritable implementation of Basic2ObjectMap */ - public static final class BasicInt2ObjectOpenHashMap - extends Basic2ObjectMap { - /** Map */ - private final Int2ObjectOpenHashMap map; - /** Value writer */ - private final WritableWriter valueWriter; - - /** - * Constructor - * - * @param valueWriter Writer of values - */ - public BasicInt2ObjectOpenHashMap(WritableWriter valueWriter) { - this.map = new Int2ObjectOpenHashMap<>(); - this.valueWriter = valueWriter; - } - - /** - * Constructor - * - * @param capacity Capacity - * @param valueWriter Writer of values - */ - public BasicInt2ObjectOpenHashMap( - int capacity, WritableWriter valueWriter) { - this.map = new Int2ObjectOpenHashMap<>(capacity); - this.valueWriter = valueWriter; - } - - @Override - public void clear() { - map.clear(); - } - - @Override - public int size() { - return map.size(); - } - - @Override - public boolean containsKey(IntWritable key) { - return map.containsKey(key.get()); - } - - @Override - public V put(IntWritable key, V value) { - return map.put(key.get(), value); - } - - @Override - public V get(IntWritable key) { - return map.get(key.get()); - } - - @Override - public V remove(IntWritable key) { - return map.remove(key.get()); - } - - @Override - public PrimitiveIdTypeOps getKeyTypeOps() { - return IntTypeOps.INSTANCE; - } - - @Override - public Iterator fastKeyIterator() { - return new ReusableIterator(map.keySet().iterator()) { - @Override - public IntWritable next() { - reusableKey.set(iter.nextInt()); - return reusableKey; - } - - @Override - public void reset() { - iter = map.keySet().iterator(); - } - }; - } - - @Override - public Iterator valueIterator() { - return map.values().iterator(); - } - - @Override - public Collection values() { - return map.values(); - } - - @Override - public void write(DataOutput out) throws IOException { - out.writeInt(map.size()); - ObjectIterator> iterator = - map.int2ObjectEntrySet().fastIterator(); - while (iterator.hasNext()) { - Int2ObjectMap.Entry entry = iterator.next(); - out.writeInt(entry.getIntKey()); - valueWriter.write(out, entry.getValue()); - } - } - - @Override - public void readFields(DataInput in) - throws IOException { - int size = in.readInt(); - map.clear(); - map.trim(size); - while (size-- > 0) { - int key = in.readInt(); - V value = valueWriter.readFields(in); - map.put(key, value); - } - } - } - - /** LongWritable implementation of Basic2ObjectMap */ - public static final class BasicLong2ObjectOpenHashMap - extends Basic2ObjectMap { - /** Map */ - private final Long2ObjectOpenHashMap map; - /** Value writer */ - private final WritableWriter valueWriter; - - /** - * Constructor - * - * @param valueWriter Writer of values - */ - public BasicLong2ObjectOpenHashMap(WritableWriter valueWriter) { - this.map = new Long2ObjectOpenHashMap<>(); - this.valueWriter = valueWriter; - } - - /** - * Constructor - * - * @param capacity Capacity - * @param valueWriter Writer of values - */ - public BasicLong2ObjectOpenHashMap( - int capacity, WritableWriter valueWriter) { - this.map = new Long2ObjectOpenHashMap<>(capacity); - this.valueWriter = valueWriter; - } - - @Override - public void clear() { - map.clear(); - } - - @Override - public int size() { - return map.size(); - } - - @Override - public boolean containsKey(LongWritable key) { - return map.containsKey(key.get()); - } - - @Override - public V put(LongWritable key, V value) { - return map.put(key.get(), value); - } - - @Override - public V get(LongWritable key) { - return map.get(key.get()); - } - - @Override - public V remove(LongWritable key) { - return map.remove(key.get()); - } - - @Override - public PrimitiveIdTypeOps getKeyTypeOps() { - return LongTypeOps.INSTANCE; - } - - @Override - public Iterator fastKeyIterator() { - return new ReusableIterator(map.keySet().iterator()) { - @Override - public LongWritable next() { - reusableKey.set(iter.nextLong()); - return reusableKey; - } - - @Override - public void reset() { - iter = map.keySet().iterator(); - } - }; - } - - @Override - public Iterator valueIterator() { - return map.values().iterator(); - } - - @Override - public Collection values() { - return map.values(); - } - - @Override - public void write(DataOutput out) throws IOException { - Preconditions.checkState( - valueWriter != null, - "valueWriter is not provided" - ); - - out.writeInt(map.size()); - ObjectIterator> iterator = - map.long2ObjectEntrySet().fastIterator(); - while (iterator.hasNext()) { - Long2ObjectMap.Entry entry = iterator.next(); - out.writeLong(entry.getLongKey()); - valueWriter.write(out, entry.getValue()); - } - } - - @Override - public void readFields(DataInput in) throws IOException { - Preconditions.checkState( - valueWriter != null, - "valueWriter is not provided" - ); - - int size = in.readInt(); - map.clear(); - map.trim(size); - while (size-- > 0) { - long key = in.readLong(); - V value = valueWriter.readFields(in); - map.put(key, value); - } - } - } - /** Writable implementation of Basic2ObjectMap */ public static final class BasicObject2ObjectOpenHashMap extends Basic2ObjectMap { diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/BasicSet.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/BasicSet.java index 919416992..da5a4a568 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/BasicSet.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/BasicSet.java @@ -17,24 +17,7 @@ */ package org.apache.giraph.types.ops.collections; -import it.unimi.dsi.fastutil.ints.IntIterator; -import it.unimi.dsi.fastutil.ints.IntOpenHashBigSet; -import it.unimi.dsi.fastutil.ints.IntOpenHashSet; -import it.unimi.dsi.fastutil.ints.IntSet; -import it.unimi.dsi.fastutil.longs.LongIterator; -import it.unimi.dsi.fastutil.longs.LongOpenHashBigSet; -import it.unimi.dsi.fastutil.longs.LongOpenHashSet; -import it.unimi.dsi.fastutil.longs.LongSet; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; - -import org.apache.giraph.types.ops.IntTypeOps; -import org.apache.giraph.types.ops.LongTypeOps; import org.apache.giraph.types.ops.PrimitiveIdTypeOps; -import org.apache.hadoop.io.IntWritable; -import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Writable; /** @@ -90,166 +73,4 @@ public interface BasicSet extends Writable { * @return TypeOps */ PrimitiveIdTypeOps getElementTypeOps(); - - /** IntWritable implementation of BasicSet */ - public static final class BasicIntOpenHashSet - implements BasicSet { - /** Set */ - private final IntSet set; - - /** Constructor */ - public BasicIntOpenHashSet() { - set = new IntOpenHashSet(); - } - - /** - * Constructor - * - * @param capacity Capacity - */ - public BasicIntOpenHashSet(long capacity) { - if (capacity <= MAX_OPEN_HASHSET_CAPACITY) { - set = new IntOpenHashSet((int) capacity); - } else { - set = new IntOpenHashBigSet(capacity); - } - } - - @Override - public void clear() { - set.clear(); - } - - @Override - public long size() { - if (set instanceof IntOpenHashBigSet) { - return ((IntOpenHashBigSet) set).size64(); - } - return set.size(); - } - - @Override - public void trim(long n) { - if (set instanceof IntOpenHashSet) { - ((IntOpenHashSet) set).trim((int) Math.max(set.size(), n)); - } else { - ((IntOpenHashBigSet) set).trim(Math.max(set.size(), n)); - } - } - - @Override - public boolean add(IntWritable value) { - return set.add(value.get()); - } - - @Override - public boolean contains(IntWritable value) { - return set.contains(value.get()); - } - - @Override - public PrimitiveIdTypeOps getElementTypeOps() { - return IntTypeOps.INSTANCE; - } - - @Override - public void write(DataOutput out) throws IOException { - out.writeInt(set.size()); - IntIterator iter = set.iterator(); - while (iter.hasNext()) { - out.writeInt(iter.nextInt()); - } - } - - @Override - public void readFields(DataInput in) throws IOException { - long size = in.readLong(); - set.clear(); - trim(size); - for (long i = 0; i < size; ++i) { - set.add(in.readInt()); - } - } - } - - /** LongWritable implementation of BasicSet */ - public static final class BasicLongOpenHashSet - implements BasicSet { - /** Set */ - private final LongSet set; - - /** Constructor */ - public BasicLongOpenHashSet() { - set = new LongOpenHashSet(); - } - - /** - * Constructor - * - * @param capacity Capacity - */ - public BasicLongOpenHashSet(long capacity) { - if (capacity <= MAX_OPEN_HASHSET_CAPACITY) { - set = new LongOpenHashSet((int) capacity); - } else { - set = new LongOpenHashBigSet(capacity); - } - } - - @Override - public void clear() { - set.clear(); - } - - @Override - public long size() { - if (set instanceof LongOpenHashBigSet) { - return ((LongOpenHashBigSet) set).size64(); - } - return set.size(); - } - - @Override - public void trim(long n) { - if (set instanceof LongOpenHashSet) { - ((LongOpenHashSet) set).trim((int) Math.max(set.size(), n)); - } else { - ((LongOpenHashBigSet) set).trim(Math.max(set.size(), n)); - } - } - - @Override - public boolean add(LongWritable value) { - return set.add(value.get()); - } - - @Override - public boolean contains(LongWritable value) { - return set.contains(value.get()); - } - - @Override - public PrimitiveIdTypeOps getElementTypeOps() { - return LongTypeOps.INSTANCE; - } - - @Override - public void write(DataOutput out) throws IOException { - out.writeLong(set.size()); - LongIterator iter = set.iterator(); - while (iter.hasNext()) { - out.writeLong(iter.nextLong()); - } - } - - @Override - public void readFields(DataInput in) throws IOException { - long size = in.readLong(); - set.clear(); - trim(size); - for (long i = 0; i < size; ++i) { - set.add(in.readLong()); - } - } - } } diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/WShortCollection.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/WShortCollection.java new file mode 100644 index 000000000..20a1493d0 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/WShortCollection.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.types.ops.collections; + +import org.apache.giraph.function.primitive.ShortConsumer; +import org.apache.giraph.function.primitive.ShortPredicate; +import org.apache.hadoop.io.ShortWritable; + +import it.unimi.dsi.fastutil.shorts.ShortCollection; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Long specialization of WCollection + */ +public interface WShortCollection + extends WCollection, ShortCollection { + /** + * Traverse all elements of the array list, calling given function on each + * element, or until predicate returns false. + * + * @param f Function to call on each element. + */ + void forEachShort(ShortConsumer f); + + /** + * Traverse all elements of the array list, calling given function on each + * element. + * + * @param f Function to call on each element. + * @return true if the predicate returned true for all elements, + * false if it returned false for some element. + */ + boolean forEachWhileShort(ShortPredicate f); +} diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WArrayList.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WArrayList.java index 0539524ee..202f1d01c 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WArrayList.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WArrayList.java @@ -70,4 +70,11 @@ public interface WArrayList extends WCollection { void fillW(int from, int to, T value); /** Sort the array in ascending order */ void sort(); + /** + * Swap elements on given positions. + * + * @param i Index of first element to swap + * @param j Index of second element to swap + */ + void swap(int i, int j); } diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WBooleanArrayList.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WBooleanArrayList.java index 213fb56eb..bf387c3ec 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WBooleanArrayList.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WBooleanArrayList.java @@ -161,6 +161,7 @@ public boolean fastForEachWhileW(Predicate f) { * * @param f Function to call on each element. */ + @Override public void forEachBoolean(BooleanConsumer f) { for (int i = 0; i < size(); ++i) { f.apply(getBoolean(i)); @@ -175,6 +176,7 @@ public void forEachBoolean(BooleanConsumer f) { * @return true if the predicate returned true for all elements, * false if it returned false for some element. */ + @Override public boolean forEachWhileBoolean(BooleanPredicate f) { for (int i = 0; i < size(); ++i) { if (!f.apply(getBoolean(i))) { @@ -189,6 +191,20 @@ public void sort() { BooleanArrays.quickSort(elements(), 0, size()); } + @Override + public void swap(int i, int j) { + int size = size(); + if (i >= size || j >= size) { + throw new IndexOutOfBoundsException( + "Index (" + Math.max(i, j) + + ") is greater than or equal to list size (" + size + ")"); + } + boolean[] arr = elements(); + boolean tmp = arr[i]; + arr[i] = arr[j]; + arr[j] = tmp; + } + @Override public void writeElements(DataOutput out) throws IOException { for (int i = 0; i < size; i++) { diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WByteArrayList.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WByteArrayList.java index 35063310f..288f8e094 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WByteArrayList.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WByteArrayList.java @@ -34,7 +34,6 @@ import org.apache.giraph.utils.Varint; import it.unimi.dsi.fastutil.bytes.ByteArrayList; -import it.unimi.dsi.fastutil.bytes.ByteArrays; import it.unimi.dsi.fastutil.bytes.ByteCollection; import it.unimi.dsi.fastutil.bytes.ByteList; @@ -161,6 +160,7 @@ public boolean fastForEachWhileW(Predicate f) { * * @param f Function to call on each element. */ + @Override public void forEachByte(ByteConsumer f) { for (int i = 0; i < size(); ++i) { f.apply(getByte(i)); @@ -175,6 +175,7 @@ public void forEachByte(ByteConsumer f) { * @return true if the predicate returned true for all elements, * false if it returned false for some element. */ + @Override public boolean forEachWhileByte(BytePredicate f) { for (int i = 0; i < size(); ++i) { if (!f.apply(getByte(i))) { @@ -186,7 +187,21 @@ public boolean forEachWhileByte(BytePredicate f) { @Override public void sort() { - ByteArrays.quickSort(elements(), 0, size()); + Arrays.sort(elements(), 0, size()); + } + + @Override + public void swap(int i, int j) { + int size = size(); + if (i >= size || j >= size) { + throw new IndexOutOfBoundsException( + "Index (" + Math.max(i, j) + + ") is greater than or equal to list size (" + size + ")"); + } + byte[] arr = elements(); + byte tmp = arr[i]; + arr[i] = arr[j]; + arr[j] = tmp; } @Override diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WDoubleArrayList.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WDoubleArrayList.java index a1a19e262..1745e7006 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WDoubleArrayList.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WDoubleArrayList.java @@ -34,7 +34,6 @@ import org.apache.giraph.utils.Varint; import it.unimi.dsi.fastutil.doubles.DoubleArrayList; -import it.unimi.dsi.fastutil.doubles.DoubleArrays; import it.unimi.dsi.fastutil.doubles.DoubleCollection; import it.unimi.dsi.fastutil.doubles.DoubleList; @@ -161,6 +160,7 @@ public boolean fastForEachWhileW(Predicate f) { * * @param f Function to call on each element. */ + @Override public void forEachDouble(DoubleConsumer f) { for (int i = 0; i < size(); ++i) { f.apply(getDouble(i)); @@ -175,6 +175,7 @@ public void forEachDouble(DoubleConsumer f) { * @return true if the predicate returned true for all elements, * false if it returned false for some element. */ + @Override public boolean forEachWhileDouble(DoublePredicate f) { for (int i = 0; i < size(); ++i) { if (!f.apply(getDouble(i))) { @@ -186,7 +187,21 @@ public boolean forEachWhileDouble(DoublePredicate f) { @Override public void sort() { - DoubleArrays.quickSort(elements(), 0, size()); + Arrays.sort(elements(), 0, size()); + } + + @Override + public void swap(int i, int j) { + int size = size(); + if (i >= size || j >= size) { + throw new IndexOutOfBoundsException( + "Index (" + Math.max(i, j) + + ") is greater than or equal to list size (" + size + ")"); + } + double[] arr = elements(); + double tmp = arr[i]; + arr[i] = arr[j]; + arr[j] = tmp; } @Override diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WFloatArrayList.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WFloatArrayList.java index 34e6a5057..8420b2f67 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WFloatArrayList.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WFloatArrayList.java @@ -34,7 +34,6 @@ import org.apache.giraph.utils.Varint; import it.unimi.dsi.fastutil.floats.FloatArrayList; -import it.unimi.dsi.fastutil.floats.FloatArrays; import it.unimi.dsi.fastutil.floats.FloatCollection; import it.unimi.dsi.fastutil.floats.FloatList; @@ -161,6 +160,7 @@ public boolean fastForEachWhileW(Predicate f) { * * @param f Function to call on each element. */ + @Override public void forEachFloat(FloatConsumer f) { for (int i = 0; i < size(); ++i) { f.apply(getFloat(i)); @@ -175,6 +175,7 @@ public void forEachFloat(FloatConsumer f) { * @return true if the predicate returned true for all elements, * false if it returned false for some element. */ + @Override public boolean forEachWhileFloat(FloatPredicate f) { for (int i = 0; i < size(); ++i) { if (!f.apply(getFloat(i))) { @@ -186,7 +187,21 @@ public boolean forEachWhileFloat(FloatPredicate f) { @Override public void sort() { - FloatArrays.quickSort(elements(), 0, size()); + Arrays.sort(elements(), 0, size()); + } + + @Override + public void swap(int i, int j) { + int size = size(); + if (i >= size || j >= size) { + throw new IndexOutOfBoundsException( + "Index (" + Math.max(i, j) + + ") is greater than or equal to list size (" + size + ")"); + } + float[] arr = elements(); + float tmp = arr[i]; + arr[i] = arr[j]; + arr[j] = tmp; } @Override diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WIntArrayList.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WIntArrayList.java index 1e3580269..040858f21 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WIntArrayList.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WIntArrayList.java @@ -34,7 +34,6 @@ import org.apache.giraph.utils.Varint; import it.unimi.dsi.fastutil.ints.IntArrayList; -import it.unimi.dsi.fastutil.ints.IntArrays; import it.unimi.dsi.fastutil.ints.IntCollection; import it.unimi.dsi.fastutil.ints.IntList; @@ -161,6 +160,7 @@ public boolean fastForEachWhileW(Predicate f) { * * @param f Function to call on each element. */ + @Override public void forEachInt(IntConsumer f) { for (int i = 0; i < size(); ++i) { f.apply(getInt(i)); @@ -175,6 +175,7 @@ public void forEachInt(IntConsumer f) { * @return true if the predicate returned true for all elements, * false if it returned false for some element. */ + @Override public boolean forEachWhileInt(IntPredicate f) { for (int i = 0; i < size(); ++i) { if (!f.apply(getInt(i))) { @@ -186,7 +187,21 @@ public boolean forEachWhileInt(IntPredicate f) { @Override public void sort() { - IntArrays.quickSort(elements(), 0, size()); + Arrays.sort(elements(), 0, size()); + } + + @Override + public void swap(int i, int j) { + int size = size(); + if (i >= size || j >= size) { + throw new IndexOutOfBoundsException( + "Index (" + Math.max(i, j) + + ") is greater than or equal to list size (" + size + ")"); + } + int[] arr = elements(); + int tmp = arr[i]; + arr[i] = arr[j]; + arr[j] = tmp; } @Override diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WLongArrayList.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WLongArrayList.java index ca2ca6fb2..517e4a5c4 100644 --- a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WLongArrayList.java +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WLongArrayList.java @@ -34,7 +34,6 @@ import org.apache.giraph.utils.Varint; import it.unimi.dsi.fastutil.longs.LongArrayList; -import it.unimi.dsi.fastutil.longs.LongArrays; import it.unimi.dsi.fastutil.longs.LongCollection; import it.unimi.dsi.fastutil.longs.LongList; @@ -161,6 +160,7 @@ public boolean fastForEachWhileW(Predicate f) { * * @param f Function to call on each element. */ + @Override public void forEachLong(LongConsumer f) { for (int i = 0; i < size(); ++i) { f.apply(getLong(i)); @@ -175,6 +175,7 @@ public void forEachLong(LongConsumer f) { * @return true if the predicate returned true for all elements, * false if it returned false for some element. */ + @Override public boolean forEachWhileLong(LongPredicate f) { for (int i = 0; i < size(); ++i) { if (!f.apply(getLong(i))) { @@ -186,7 +187,21 @@ public boolean forEachWhileLong(LongPredicate f) { @Override public void sort() { - LongArrays.quickSort(elements(), 0, size()); + Arrays.sort(elements(), 0, size()); + } + + @Override + public void swap(int i, int j) { + int size = size(); + if (i >= size || j >= size) { + throw new IndexOutOfBoundsException( + "Index (" + Math.max(i, j) + + ") is greater than or equal to list size (" + size + ")"); + } + long[] arr = elements(); + long tmp = arr[i]; + arr[i] = arr[j]; + arr[j] = tmp; } @Override diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WShortArrayList.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WShortArrayList.java new file mode 100644 index 000000000..123446e9d --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/array/WShortArrayList.java @@ -0,0 +1,320 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.types.ops.collections.array; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.Arrays; + +import org.apache.giraph.function.Consumer; +import org.apache.giraph.function.Predicate; +import org.apache.giraph.function.primitive.ShortConsumer; +import org.apache.giraph.function.primitive.ShortPredicate; +import org.apache.giraph.types.ops.ShortTypeOps; +import org.apache.giraph.types.ops.PrimitiveTypeOps; +import org.apache.giraph.types.ops.collections.ResettableIterator; +import org.apache.giraph.types.ops.collections.WShortCollection; +import org.apache.hadoop.io.ShortWritable; +import org.apache.giraph.utils.Varint; + +import it.unimi.dsi.fastutil.shorts.ShortArrayList; +import it.unimi.dsi.fastutil.shorts.ShortCollection; +import it.unimi.dsi.fastutil.shorts.ShortList; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** + * Writable extension of ShortArrayList, as well as + * ShortWritable implementation of WArrayList. + */ +public class WShortArrayList + extends ShortArrayList + implements WArrayList, WShortCollection { + /** + * Creates a new array list with {@link #DEFAULT_INITIAL_CAPACITY} capacity. + */ + public WShortArrayList() { + super(); + } + + /** + * Creates a new array list with given capacity. + * + * @param capacity the initial capacity of the array list (may be 0). + */ + public WShortArrayList(int capacity) { + super(capacity); + } + + /** + * Creates a new array list and fills it with a given type-specific + * collection. + * + * @param c a type-specific collection that will be used to fill the array + * list. + */ + public WShortArrayList(ShortCollection c) { + super(c); + } + + /** + * Creates a new array list and fills it with a given type-specific list. + * + * @param l a type-specific list that will be used to fill the array list. + */ + public WShortArrayList(ShortList l) { + super(l); + } + + @Override + public PrimitiveTypeOps getElementTypeOps() { + return ShortTypeOps.INSTANCE; + } + + @Override + public int capacity() { + return elements().length; + } + + @Override + public void setCapacity(int n) { + if (n >= capacity()) { + ensureCapacity(n); + } else { + trim(n); + } + } + + @Override + public void addW(ShortWritable value) { + add(value.get()); + } + + @Override + public void getIntoW(int index, ShortWritable to) { + to.set(getShort(index)); + } + + @Override + public void popIntoW(ShortWritable to) { + to.set(popShort()); + } + + @Override + public void setW(int index, ShortWritable value) { + set(index, value.get()); + } + + @Override + public void fillW(int from, int to, ShortWritable value) { + if (to > size()) { + throw new ArrayIndexOutOfBoundsException( + "End index (" + to + ") is greater than array length (" + + size() + ")"); + } + Arrays.fill(elements(), from, to, value.get()); + } + + @Override + public ResettableIterator fastIteratorW() { + return fastIteratorW(getElementTypeOps().create()); + } + + @Override + public ResettableIterator fastIteratorW( + ShortWritable iterationValue) { + return WArrayListPrivateUtils.fastIterator(this, iterationValue); + } + + @Override + public void fastForEachW(Consumer f) { + WArrayListPrivateUtils.fastForEach(this, f, getElementTypeOps().create()); + } + + @Override + public boolean fastForEachWhileW(Predicate f) { + return WArrayListPrivateUtils.fastForEachWhile( + this, f, getElementTypeOps().create()); + } + + /** + * Traverse all elements of the array list, calling given function on each + * element, or until predicate returns false. + * + * @param f Function to call on each element. + */ + @Override + public void forEachShort(ShortConsumer f) { + for (int i = 0; i < size(); ++i) { + f.apply(getShort(i)); + } + } + + /** + * Traverse all elements of the array list, calling given function on each + * element. + * + * @param f Function to call on each element. + * @return true if the predicate returned true for all elements, + * false if it returned false for some element. + */ + @Override + public boolean forEachWhileShort(ShortPredicate f) { + for (int i = 0; i < size(); ++i) { + if (!f.apply(getShort(i))) { + return false; + } + } + return true; + } + + @Override + public void sort() { + Arrays.sort(elements(), 0, size()); + } + + @Override + public void swap(int i, int j) { + int size = size(); + if (i >= size || j >= size) { + throw new IndexOutOfBoundsException( + "Index (" + Math.max(i, j) + + ") is greater than or equal to list size (" + size + ")"); + } + short[] arr = elements(); + short tmp = arr[i]; + arr[i] = arr[j]; + arr[j] = tmp; + } + + @Override + public void writeElements(DataOutput out) throws IOException { + for (int i = 0; i < size; i++) { + out.writeShort(a[i]); + } + } + + @Override + public void write(DataOutput out) throws IOException { + Varint.writeUnsignedVarInt(size, out); + writeElements(out); + } + + @Override + public void readElements(DataInput in, int size) throws IOException { + this.size = size; + resizeArrayForRead(size); + for (int i = 0; i < size; i++) { + a[i] = in.readShort(); + } + } + + /** + * Resize array for reading given number of elements. + * @param size Number of elements that will be read. + */ + protected void resizeArrayForRead(int size) { + if (size != a.length) { + a = new short[size]; + } + } + + @Override + public void readFields(DataInput in) throws IOException { + readElements(in, Varint.readUnsignedVarInt(in)); + } + + /** + * Write a potentially null list to a DataOutput. Null list is written + * equivalently as an empty list. Use WritableUtils.writeIfNotNullAndObject + * if distinction is needed. + * + * @param list Array list to be written + * @param out Data output + */ + public static void writeOrNull(WShortArrayList list, DataOutput out) + throws IOException { + if (list == null) { + Varint.writeUnsignedVarInt(0, out); + } else { + list.write(out); + } + } + + /** + * Read array list from the DataInput stream into a newly created object. + * + * @param in Data input + * @return New read array list object. + */ + public static WShortArrayList readNew(DataInput in) throws IOException { + int size = Varint.readSignedVarInt(in); + WShortArrayList list = new WShortArrayList(size); + list.readElements(in, size); + return list; + } + + /** + * Variant of WShortArrayList that doesn't reallocate smaller backing + * array on consecutive readFields/readElements calls, and so is suitable for + * reusable use. + * (and backing array will only grow on readFields/readElements calls) + */ + public static class WReusableShortArrayList + extends WShortArrayList { + /** Constructor */ + public WReusableShortArrayList() { + super(); + } + + /** + * Constructor + * @param capacity Capacity + */ + public WReusableShortArrayList(int capacity) { + super(capacity); + } + + @Override + protected void resizeArrayForRead(int size) { + if (size > a.length) { + a = new short[size]; + } + } + + /** + * Read array list from DataInput stream, into a given list if not null, + * or creating a new list if given list is null. + * + * @param list Array list to be written + * @param in Data input + * @return Passed array list, or a new one if null is passed + */ + public static WReusableShortArrayList readIntoOrCreate( + WReusableShortArrayList list, DataInput in) throws IOException { + int size = Varint.readUnsignedVarInt(in); + if (list == null) { + list = new WReusableShortArrayList(size); + } + list.readElements(in, size); + return list; + } + } +} diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/map/BasicByte2ObjectOpenHashMap.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/map/BasicByte2ObjectOpenHashMap.java new file mode 100644 index 000000000..ef921b216 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/map/BasicByte2ObjectOpenHashMap.java @@ -0,0 +1,169 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.types.ops.collections.map; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.Collection; +import java.util.Iterator; + +import org.apache.giraph.types.ops.ByteTypeOps; +import org.apache.giraph.types.ops.PrimitiveIdTypeOps; +import org.apache.giraph.types.ops.collections.Basic2ObjectMap; +import org.apache.giraph.types.ops.collections.WritableWriter; +import org.apache.giraph.types.ops.collections.Basic2ObjectMap.ReusableIterator; +import org.apache.hadoop.io.ByteWritable; + +import com.google.common.base.Preconditions; + +import it.unimi.dsi.fastutil.bytes.Byte2ObjectMap; +import it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.bytes.ByteIterator; +import it.unimi.dsi.fastutil.bytes.Byte2ObjectMap.Entry; +import it.unimi.dsi.fastutil.objects.ObjectIterator; + +/** + * ByteWritable implementation of Basic2ObjectMap. + * + * @param Value type + */ +public final class BasicByte2ObjectOpenHashMap + extends Basic2ObjectMap { + /** Map */ + private final Byte2ObjectOpenHashMap map; + /** Value writer */ + private final WritableWriter valueWriter; + + /** + * Constructor + * + * @param valueWriter Writer of values + */ + public BasicByte2ObjectOpenHashMap(WritableWriter valueWriter) { + this.map = new Byte2ObjectOpenHashMap<>(); + this.valueWriter = valueWriter; + } + + /** + * Constructor + * + * @param capacity Capacity + * @param valueWriter Writer of values + */ + public BasicByte2ObjectOpenHashMap( + int capacity, WritableWriter valueWriter) { + this.map = new Byte2ObjectOpenHashMap<>(capacity); + this.valueWriter = valueWriter; + } + + @Override + public void clear() { + map.clear(); + } + + @Override + public int size() { + return map.size(); + } + + @Override + public boolean containsKey(ByteWritable key) { + return map.containsKey(key.get()); + } + + @Override + public V put(ByteWritable key, V value) { + return map.put(key.get(), value); + } + + @Override + public V get(ByteWritable key) { + return map.get(key.get()); + } + + @Override + public V remove(ByteWritable key) { + return map.remove(key.get()); + } + + @Override + public PrimitiveIdTypeOps getKeyTypeOps() { + return ByteTypeOps.INSTANCE; + } + + @Override + public Iterator fastKeyIterator() { + return new ReusableIterator(map.keySet().iterator()) { + @Override + public ByteWritable next() { + reusableKey.set(iter.nextByte()); + return reusableKey; + } + + @Override + public void reset() { + iter = map.keySet().iterator(); + } + }; + } + + @Override + public Iterator valueIterator() { + return map.values().iterator(); + } + + @Override + public Collection values() { + return map.values(); + } + + @Override + public void write(DataOutput out) throws IOException { + Preconditions.checkState( + valueWriter != null, + "valueWriter is not provided" + ); + + out.writeInt(map.size()); + ObjectIterator> iterator = + map.byte2ObjectEntrySet().fastIterator(); + while (iterator.hasNext()) { + Byte2ObjectMap.Entry entry = iterator.next(); + out.writeByte(entry.getByteKey()); + valueWriter.write(out, entry.getValue()); + } + } + + @Override + public void readFields(DataInput in) throws IOException { + Preconditions.checkState( + valueWriter != null, + "valueWriter is not provided" + ); + + int size = in.readInt(); + map.clear(); + map.trim(size); + while (size-- > 0) { + byte key = in.readByte(); + V value = valueWriter.readFields(in); + map.put(key, value); + } + } +} diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/map/BasicInt2ObjectOpenHashMap.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/map/BasicInt2ObjectOpenHashMap.java new file mode 100644 index 000000000..d18bc3e0d --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/map/BasicInt2ObjectOpenHashMap.java @@ -0,0 +1,169 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.types.ops.collections.map; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.Collection; +import java.util.Iterator; + +import org.apache.giraph.types.ops.IntTypeOps; +import org.apache.giraph.types.ops.PrimitiveIdTypeOps; +import org.apache.giraph.types.ops.collections.Basic2ObjectMap; +import org.apache.giraph.types.ops.collections.WritableWriter; +import org.apache.giraph.types.ops.collections.Basic2ObjectMap.ReusableIterator; +import org.apache.hadoop.io.IntWritable; + +import com.google.common.base.Preconditions; + +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntIterator; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap.Entry; +import it.unimi.dsi.fastutil.objects.ObjectIterator; + +/** + * IntWritable implementation of Basic2ObjectMap. + * + * @param Value type + */ +public final class BasicInt2ObjectOpenHashMap + extends Basic2ObjectMap { + /** Map */ + private final Int2ObjectOpenHashMap map; + /** Value writer */ + private final WritableWriter valueWriter; + + /** + * Constructor + * + * @param valueWriter Writer of values + */ + public BasicInt2ObjectOpenHashMap(WritableWriter valueWriter) { + this.map = new Int2ObjectOpenHashMap<>(); + this.valueWriter = valueWriter; + } + + /** + * Constructor + * + * @param capacity Capacity + * @param valueWriter Writer of values + */ + public BasicInt2ObjectOpenHashMap( + int capacity, WritableWriter valueWriter) { + this.map = new Int2ObjectOpenHashMap<>(capacity); + this.valueWriter = valueWriter; + } + + @Override + public void clear() { + map.clear(); + } + + @Override + public int size() { + return map.size(); + } + + @Override + public boolean containsKey(IntWritable key) { + return map.containsKey(key.get()); + } + + @Override + public V put(IntWritable key, V value) { + return map.put(key.get(), value); + } + + @Override + public V get(IntWritable key) { + return map.get(key.get()); + } + + @Override + public V remove(IntWritable key) { + return map.remove(key.get()); + } + + @Override + public PrimitiveIdTypeOps getKeyTypeOps() { + return IntTypeOps.INSTANCE; + } + + @Override + public Iterator fastKeyIterator() { + return new ReusableIterator(map.keySet().iterator()) { + @Override + public IntWritable next() { + reusableKey.set(iter.nextInt()); + return reusableKey; + } + + @Override + public void reset() { + iter = map.keySet().iterator(); + } + }; + } + + @Override + public Iterator valueIterator() { + return map.values().iterator(); + } + + @Override + public Collection values() { + return map.values(); + } + + @Override + public void write(DataOutput out) throws IOException { + Preconditions.checkState( + valueWriter != null, + "valueWriter is not provided" + ); + + out.writeInt(map.size()); + ObjectIterator> iterator = + map.int2ObjectEntrySet().fastIterator(); + while (iterator.hasNext()) { + Int2ObjectMap.Entry entry = iterator.next(); + out.writeInt(entry.getIntKey()); + valueWriter.write(out, entry.getValue()); + } + } + + @Override + public void readFields(DataInput in) throws IOException { + Preconditions.checkState( + valueWriter != null, + "valueWriter is not provided" + ); + + int size = in.readInt(); + map.clear(); + map.trim(size); + while (size-- > 0) { + int key = in.readInt(); + V value = valueWriter.readFields(in); + map.put(key, value); + } + } +} diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/map/BasicLong2ObjectOpenHashMap.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/map/BasicLong2ObjectOpenHashMap.java new file mode 100644 index 000000000..86743b763 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/map/BasicLong2ObjectOpenHashMap.java @@ -0,0 +1,169 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.types.ops.collections.map; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.Collection; +import java.util.Iterator; + +import org.apache.giraph.types.ops.LongTypeOps; +import org.apache.giraph.types.ops.PrimitiveIdTypeOps; +import org.apache.giraph.types.ops.collections.Basic2ObjectMap; +import org.apache.giraph.types.ops.collections.WritableWriter; +import org.apache.giraph.types.ops.collections.Basic2ObjectMap.ReusableIterator; +import org.apache.hadoop.io.LongWritable; + +import com.google.common.base.Preconditions; + +import it.unimi.dsi.fastutil.longs.Long2ObjectMap; +import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.longs.LongIterator; +import it.unimi.dsi.fastutil.longs.Long2ObjectMap.Entry; +import it.unimi.dsi.fastutil.objects.ObjectIterator; + +/** + * LongWritable implementation of Basic2ObjectMap. + * + * @param Value type + */ +public final class BasicLong2ObjectOpenHashMap + extends Basic2ObjectMap { + /** Map */ + private final Long2ObjectOpenHashMap map; + /** Value writer */ + private final WritableWriter valueWriter; + + /** + * Constructor + * + * @param valueWriter Writer of values + */ + public BasicLong2ObjectOpenHashMap(WritableWriter valueWriter) { + this.map = new Long2ObjectOpenHashMap<>(); + this.valueWriter = valueWriter; + } + + /** + * Constructor + * + * @param capacity Capacity + * @param valueWriter Writer of values + */ + public BasicLong2ObjectOpenHashMap( + int capacity, WritableWriter valueWriter) { + this.map = new Long2ObjectOpenHashMap<>(capacity); + this.valueWriter = valueWriter; + } + + @Override + public void clear() { + map.clear(); + } + + @Override + public int size() { + return map.size(); + } + + @Override + public boolean containsKey(LongWritable key) { + return map.containsKey(key.get()); + } + + @Override + public V put(LongWritable key, V value) { + return map.put(key.get(), value); + } + + @Override + public V get(LongWritable key) { + return map.get(key.get()); + } + + @Override + public V remove(LongWritable key) { + return map.remove(key.get()); + } + + @Override + public PrimitiveIdTypeOps getKeyTypeOps() { + return LongTypeOps.INSTANCE; + } + + @Override + public Iterator fastKeyIterator() { + return new ReusableIterator(map.keySet().iterator()) { + @Override + public LongWritable next() { + reusableKey.set(iter.nextLong()); + return reusableKey; + } + + @Override + public void reset() { + iter = map.keySet().iterator(); + } + }; + } + + @Override + public Iterator valueIterator() { + return map.values().iterator(); + } + + @Override + public Collection values() { + return map.values(); + } + + @Override + public void write(DataOutput out) throws IOException { + Preconditions.checkState( + valueWriter != null, + "valueWriter is not provided" + ); + + out.writeInt(map.size()); + ObjectIterator> iterator = + map.long2ObjectEntrySet().fastIterator(); + while (iterator.hasNext()) { + Long2ObjectMap.Entry entry = iterator.next(); + out.writeLong(entry.getLongKey()); + valueWriter.write(out, entry.getValue()); + } + } + + @Override + public void readFields(DataInput in) throws IOException { + Preconditions.checkState( + valueWriter != null, + "valueWriter is not provided" + ); + + int size = in.readInt(); + map.clear(); + map.trim(size); + while (size-- > 0) { + long key = in.readLong(); + V value = valueWriter.readFields(in); + map.put(key, value); + } + } +} diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/map/BasicShort2ObjectOpenHashMap.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/map/BasicShort2ObjectOpenHashMap.java new file mode 100644 index 000000000..08ed16fce --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/map/BasicShort2ObjectOpenHashMap.java @@ -0,0 +1,169 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.types.ops.collections.map; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.Collection; +import java.util.Iterator; + +import org.apache.giraph.types.ops.ShortTypeOps; +import org.apache.giraph.types.ops.PrimitiveIdTypeOps; +import org.apache.giraph.types.ops.collections.Basic2ObjectMap; +import org.apache.giraph.types.ops.collections.WritableWriter; +import org.apache.giraph.types.ops.collections.Basic2ObjectMap.ReusableIterator; +import org.apache.hadoop.io.ShortWritable; + +import com.google.common.base.Preconditions; + +import it.unimi.dsi.fastutil.shorts.Short2ObjectMap; +import it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.shorts.ShortIterator; +import it.unimi.dsi.fastutil.shorts.Short2ObjectMap.Entry; +import it.unimi.dsi.fastutil.objects.ObjectIterator; + +/** + * ShortWritable implementation of Basic2ObjectMap. + * + * @param Value type + */ +public final class BasicShort2ObjectOpenHashMap + extends Basic2ObjectMap { + /** Map */ + private final Short2ObjectOpenHashMap map; + /** Value writer */ + private final WritableWriter valueWriter; + + /** + * Constructor + * + * @param valueWriter Writer of values + */ + public BasicShort2ObjectOpenHashMap(WritableWriter valueWriter) { + this.map = new Short2ObjectOpenHashMap<>(); + this.valueWriter = valueWriter; + } + + /** + * Constructor + * + * @param capacity Capacity + * @param valueWriter Writer of values + */ + public BasicShort2ObjectOpenHashMap( + int capacity, WritableWriter valueWriter) { + this.map = new Short2ObjectOpenHashMap<>(capacity); + this.valueWriter = valueWriter; + } + + @Override + public void clear() { + map.clear(); + } + + @Override + public int size() { + return map.size(); + } + + @Override + public boolean containsKey(ShortWritable key) { + return map.containsKey(key.get()); + } + + @Override + public V put(ShortWritable key, V value) { + return map.put(key.get(), value); + } + + @Override + public V get(ShortWritable key) { + return map.get(key.get()); + } + + @Override + public V remove(ShortWritable key) { + return map.remove(key.get()); + } + + @Override + public PrimitiveIdTypeOps getKeyTypeOps() { + return ShortTypeOps.INSTANCE; + } + + @Override + public Iterator fastKeyIterator() { + return new ReusableIterator(map.keySet().iterator()) { + @Override + public ShortWritable next() { + reusableKey.set(iter.nextShort()); + return reusableKey; + } + + @Override + public void reset() { + iter = map.keySet().iterator(); + } + }; + } + + @Override + public Iterator valueIterator() { + return map.values().iterator(); + } + + @Override + public Collection values() { + return map.values(); + } + + @Override + public void write(DataOutput out) throws IOException { + Preconditions.checkState( + valueWriter != null, + "valueWriter is not provided" + ); + + out.writeInt(map.size()); + ObjectIterator> iterator = + map.short2ObjectEntrySet().fastIterator(); + while (iterator.hasNext()) { + Short2ObjectMap.Entry entry = iterator.next(); + out.writeShort(entry.getShortKey()); + valueWriter.write(out, entry.getValue()); + } + } + + @Override + public void readFields(DataInput in) throws IOException { + Preconditions.checkState( + valueWriter != null, + "valueWriter is not provided" + ); + + int size = in.readInt(); + map.clear(); + map.trim(size); + while (size-- > 0) { + short key = in.readShort(); + V value = valueWriter.readFields(in); + map.put(key, value); + } + } +} diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/map/package-info.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/map/package-info.java new file mode 100644 index 000000000..f0123637d --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/map/package-info.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Map classes. + */ +package org.apache.giraph.types.ops.collections.map; diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/set/BasicByteOpenHashSet.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/set/BasicByteOpenHashSet.java new file mode 100644 index 000000000..7a517cd73 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/set/BasicByteOpenHashSet.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.types.ops.collections.set; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +import org.apache.giraph.types.ops.ByteTypeOps; +import org.apache.giraph.types.ops.PrimitiveIdTypeOps; +import org.apache.giraph.types.ops.collections.BasicSet; +import org.apache.giraph.utils.Varint; +import org.apache.hadoop.io.ByteWritable; + +import it.unimi.dsi.fastutil.bytes.ByteIterator; +import it.unimi.dsi.fastutil.bytes.ByteOpenHashSet; +import it.unimi.dsi.fastutil.bytes.ByteSet; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** ByteWritable implementation of BasicSet */ +public final class BasicByteOpenHashSet + implements BasicSet { + /** Set */ + private final ByteSet set; + + /** Constructor */ + public BasicByteOpenHashSet() { + set = new ByteOpenHashSet(); + } + + /** + * Constructor + * + * @param capacity Capacity + */ + public BasicByteOpenHashSet(int capacity) { + set = new ByteOpenHashSet(capacity); + } + + @Override + public void clear() { + set.clear(); + } + + @Override + public long size() { + return set.size(); + } + + @Override + public void trim(long n) { + ((ByteOpenHashSet) set).trim((int) Math.max(set.size(), n)); + } + + @Override + public boolean add(ByteWritable value) { + return set.add(value.get()); + } + + @Override + public boolean contains(ByteWritable value) { + return set.contains(value.get()); + } + + @Override + public PrimitiveIdTypeOps getElementTypeOps() { + return ByteTypeOps.INSTANCE; + } + + @Override + public void write(DataOutput out) throws IOException { + Varint.writeUnsignedVarInt(set.size(), out); + ByteIterator iter = set.iterator(); + while (iter.hasNext()) { + out.writeByte(iter.nextByte()); + } + } + + @Override + public void readFields(DataInput in) throws IOException { + int size = Varint.readUnsignedVarInt(in); + set.clear(); + trim(size); + for (int i = 0; i < size; ++i) { + set.add(in.readByte()); + } + } +} diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/set/BasicIntOpenHashSet.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/set/BasicIntOpenHashSet.java new file mode 100644 index 000000000..99e1af43a --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/set/BasicIntOpenHashSet.java @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.types.ops.collections.set; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +import org.apache.giraph.types.ops.IntTypeOps; +import org.apache.giraph.types.ops.PrimitiveIdTypeOps; +import org.apache.giraph.types.ops.collections.BasicSet; +import org.apache.giraph.utils.Varint; +import org.apache.hadoop.io.IntWritable; + +import it.unimi.dsi.fastutil.ints.IntIterator; +import it.unimi.dsi.fastutil.ints.IntOpenHashBigSet; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** IntWritable implementation of BasicSet */ +public final class BasicIntOpenHashSet + implements BasicSet { + /** Set */ + private final IntSet set; + + /** Constructor */ + public BasicIntOpenHashSet() { + set = new IntOpenHashSet(); + } + + /** + * Constructor + * + * @param capacity Capacity + */ + public BasicIntOpenHashSet(long capacity) { + if (capacity <= MAX_OPEN_HASHSET_CAPACITY) { + set = new IntOpenHashSet((int) capacity); + } else { + set = new IntOpenHashBigSet(capacity); + } + } + + @Override + public void clear() { + set.clear(); + } + + @Override + public long size() { + if (set instanceof IntOpenHashBigSet) { + return ((IntOpenHashBigSet) set).size64(); + } + return set.size(); + } + + @Override + public void trim(long n) { + if (set instanceof IntOpenHashSet) { + ((IntOpenHashSet) set).trim((int) Math.max(set.size(), n)); + } else { + ((IntOpenHashBigSet) set).trim(Math.max(set.size(), n)); + } + } + + @Override + public boolean add(IntWritable value) { + return set.add(value.get()); + } + + @Override + public boolean contains(IntWritable value) { + return set.contains(value.get()); + } + + @Override + public PrimitiveIdTypeOps getElementTypeOps() { + return IntTypeOps.INSTANCE; + } + + @Override + public void write(DataOutput out) throws IOException { + Varint.writeUnsignedVarLong(size(), out); + IntIterator iter = set.iterator(); + while (iter.hasNext()) { + out.writeInt(iter.nextInt()); + } + } + + @Override + public void readFields(DataInput in) throws IOException { + long size = Varint.readUnsignedVarLong(in); + set.clear(); + trim(size); + for (long i = 0; i < size; ++i) { + set.add(in.readInt()); + } + } +} diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/set/BasicLongOpenHashSet.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/set/BasicLongOpenHashSet.java new file mode 100644 index 000000000..4527000c4 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/set/BasicLongOpenHashSet.java @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.types.ops.collections.set; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +import org.apache.giraph.types.ops.LongTypeOps; +import org.apache.giraph.types.ops.PrimitiveIdTypeOps; +import org.apache.giraph.types.ops.collections.BasicSet; +import org.apache.giraph.utils.Varint; +import org.apache.hadoop.io.LongWritable; + +import it.unimi.dsi.fastutil.longs.LongIterator; +import it.unimi.dsi.fastutil.longs.LongOpenHashBigSet; +import it.unimi.dsi.fastutil.longs.LongOpenHashSet; +import it.unimi.dsi.fastutil.longs.LongSet; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** LongWritable implementation of BasicSet */ +public final class BasicLongOpenHashSet + implements BasicSet { + /** Set */ + private final LongSet set; + + /** Constructor */ + public BasicLongOpenHashSet() { + set = new LongOpenHashSet(); + } + + /** + * Constructor + * + * @param capacity Capacity + */ + public BasicLongOpenHashSet(long capacity) { + if (capacity <= MAX_OPEN_HASHSET_CAPACITY) { + set = new LongOpenHashSet((int) capacity); + } else { + set = new LongOpenHashBigSet(capacity); + } + } + + @Override + public void clear() { + set.clear(); + } + + @Override + public long size() { + if (set instanceof LongOpenHashBigSet) { + return ((LongOpenHashBigSet) set).size64(); + } + return set.size(); + } + + @Override + public void trim(long n) { + if (set instanceof LongOpenHashSet) { + ((LongOpenHashSet) set).trim((int) Math.max(set.size(), n)); + } else { + ((LongOpenHashBigSet) set).trim(Math.max(set.size(), n)); + } + } + + @Override + public boolean add(LongWritable value) { + return set.add(value.get()); + } + + @Override + public boolean contains(LongWritable value) { + return set.contains(value.get()); + } + + @Override + public PrimitiveIdTypeOps getElementTypeOps() { + return LongTypeOps.INSTANCE; + } + + @Override + public void write(DataOutput out) throws IOException { + Varint.writeUnsignedVarLong(size(), out); + LongIterator iter = set.iterator(); + while (iter.hasNext()) { + out.writeLong(iter.nextLong()); + } + } + + @Override + public void readFields(DataInput in) throws IOException { + long size = Varint.readUnsignedVarLong(in); + set.clear(); + trim(size); + for (long i = 0; i < size; ++i) { + set.add(in.readLong()); + } + } +} diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/set/BasicShortOpenHashSet.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/set/BasicShortOpenHashSet.java new file mode 100644 index 000000000..5e5e293fe --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/set/BasicShortOpenHashSet.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.types.ops.collections.set; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +import org.apache.giraph.types.ops.ShortTypeOps; +import org.apache.giraph.types.ops.PrimitiveIdTypeOps; +import org.apache.giraph.types.ops.collections.BasicSet; +import org.apache.giraph.utils.Varint; +import org.apache.hadoop.io.ShortWritable; + +import it.unimi.dsi.fastutil.shorts.ShortIterator; +import it.unimi.dsi.fastutil.shorts.ShortOpenHashSet; +import it.unimi.dsi.fastutil.shorts.ShortSet; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +/** ShortWritable implementation of BasicSet */ +public final class BasicShortOpenHashSet + implements BasicSet { + /** Set */ + private final ShortSet set; + + /** Constructor */ + public BasicShortOpenHashSet() { + set = new ShortOpenHashSet(); + } + + /** + * Constructor + * + * @param capacity Capacity + */ + public BasicShortOpenHashSet(int capacity) { + set = new ShortOpenHashSet(capacity); + } + + @Override + public void clear() { + set.clear(); + } + + @Override + public long size() { + return set.size(); + } + + @Override + public void trim(long n) { + ((ShortOpenHashSet) set).trim((int) Math.max(set.size(), n)); + } + + @Override + public boolean add(ShortWritable value) { + return set.add(value.get()); + } + + @Override + public boolean contains(ShortWritable value) { + return set.contains(value.get()); + } + + @Override + public PrimitiveIdTypeOps getElementTypeOps() { + return ShortTypeOps.INSTANCE; + } + + @Override + public void write(DataOutput out) throws IOException { + Varint.writeUnsignedVarInt(set.size(), out); + ShortIterator iter = set.iterator(); + while (iter.hasNext()) { + out.writeShort(iter.nextShort()); + } + } + + @Override + public void readFields(DataInput in) throws IOException { + int size = Varint.readUnsignedVarInt(in); + set.clear(); + trim(size); + for (int i = 0; i < size; ++i) { + set.add(in.readShort()); + } + } +} diff --git a/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/set/package-info.java b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/set/package-info.java new file mode 100644 index 000000000..557932dce --- /dev/null +++ b/giraph-core/src/main/java/org/apache/giraph/types/ops/collections/set/package-info.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Set classes. + */ +package org.apache.giraph.types.ops.collections.set; diff --git a/giraph-core/src/main/java/org/apache/hadoop/io/ShortWritable.java b/giraph-core/src/main/java/org/apache/hadoop/io/ShortWritable.java new file mode 100644 index 000000000..169f73a45 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/hadoop/io/ShortWritable.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.io; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +/** A WritableComparable for ints. */ +public class ShortWritable implements WritableComparable { + /** value */ + private short value; + + /** Constructor */ + public ShortWritable() { } + + /** + * Constructor + * @param value value + */ + public ShortWritable(short value) { + set(value); + } + + /** + * Set the value of this ShortWritable. + * @param value value + */ + public void set(short value) { + this.value = value; + } + + /** + * Return the value of this ShortWritable. + * @return value + */ + public short get() { + return value; + } + + @Override + public void readFields(DataInput in) throws IOException { + value = in.readShort(); + } + + @Override + public void write(DataOutput out) throws IOException { + out.writeShort(value); + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof ShortWritable)) { + return false; + } + ShortWritable other = (ShortWritable) o; + return this.value == other.value; + } + + @Override + public int hashCode() { + return value; + } + + @Override + public int compareTo(Object o) { + int thisValue = this.value; + int thatValue = ((ShortWritable) o).value; + return thisValue < thatValue ? -1 : (thisValue == thatValue ? 0 : 1); + } + + @Override + public String toString() { + return Short.toString(value); + } + + /** A Comparator optimized for IntWritable. */ + public static class Comparator extends WritableComparator { + /** Constructor */ + public Comparator() { + super(ShortWritable.class); + } + + @Override + public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) { + short thisValue = (short) readUnsignedShort(b1, s1); + short thatValue = (short) readUnsignedShort(b2, s2); + return thisValue < thatValue ? -1 : (thisValue == thatValue ? 0 : 1); + } + } + + static { // register this comparator + WritableComparator.define(ShortWritable.class, new Comparator()); + } +} diff --git a/giraph-core/src/main/java/org/apache/hadoop/io/package-info.java b/giraph-core/src/main/java/org/apache/hadoop/io/package-info.java new file mode 100644 index 000000000..813debe70 --- /dev/null +++ b/giraph-core/src/main/java/org/apache/hadoop/io/package-info.java @@ -0,0 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Hadoop writable package. + */ +package org.apache.hadoop.io; diff --git a/giraph-core/src/test/java/org/apache/giraph/generate/GeneratePrimitiveClasses.java b/giraph-core/src/test/java/org/apache/giraph/generate/GeneratePrimitiveClasses.java index df1211c93..da1c77a09 100644 --- a/giraph-core/src/test/java/org/apache/giraph/generate/GeneratePrimitiveClasses.java +++ b/giraph-core/src/test/java/org/apache/giraph/generate/GeneratePrimitiveClasses.java @@ -69,16 +69,22 @@ public static enum PrimitiveType { private final boolean id; private final boolean floating; private final boolean hasWritable; + private final boolean opNeedCast; + private final boolean hasBigFastutil; private PrimitiveType(String name) { this.name = name; this.nameLower = name.toLowerCase(); this.boxed = "Int".equals(name) ? "Integer" : name; this.numeric = !"Boolean".equals(name); - this.id = "Int".equals(name) || "Long".equals(name); + this.id = + "Int".equals(name) || "Long".equals(name) || "Short".equals(name) || "Byte".equals(name); this.floating = "Float".equals(name) || "Double".equals(name); - // For some reason there is no ShortWritable in current Hadoop version - this.hasWritable = !"Short".equals(name); + // For some reason there is no ShortWritable in current Hadoop version, so we use a copy + this.hasWritable = true; + this.opNeedCast = "Short".equals(name) || "Byte".equals(name); + this.hasBigFastutil = + "Int".equals(name) || "Long".equals(name) || "Float".equals(name) || "Double".equals(name); } public String getName() { @@ -112,6 +118,14 @@ public boolean isFloating() { public boolean hasWritable() { return hasWritable; } + + public boolean isOpNeedCast() { + return opNeedCast; + } + + public boolean hasBigFastutil() { + return hasBigFastutil; + } } public static void main(String[] args) throws Exception { @@ -122,7 +136,7 @@ public static void main(String[] args) throws Exception { cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); String[] primitiveFunctions = { - "%sConsumer", "%sPredicate", "Obj2%sFunction", "%s2ObjFunction", "%s2%sFunction" + "%sConsumer", "%sPredicate", "Obj2%sFunction", "%s2ObjFunction" }; for (String function: primitiveFunctions) { @@ -155,6 +169,10 @@ public static void main(String[] args) throws Exception { } } + EnumSet mainIds = EnumSet.of(PrimitiveType.INT, PrimitiveType.LONG); + EnumSet mainTypes = EnumSet.of( + PrimitiveType.INT, PrimitiveType.LONG, PrimitiveType.FLOAT, PrimitiveType.DOUBLE); + generateForAll( cfg, writableSet, @@ -173,6 +191,18 @@ public static void main(String[] args) throws Exception { "WTypeArrayList.java", "src/main/java/org/apache/giraph/types/ops/collections/array/W%sArrayList.java"); + generateForAll( + cfg, + ids, + "BasicTypeOpenHashSet.java", + "src/main/java/org/apache/giraph/types/ops/collections/set/Basic%sOpenHashSet.java"); + + generateForAll( + cfg, + ids, + "BasicType2ObjectOpenHashMap.java", + "src/main/java/org/apache/giraph/types/ops/collections/map/Basic%s2ObjectOpenHashMap.java"); + generateForAll( cfg, writableSet, @@ -189,21 +219,28 @@ public static void main(String[] args) throws Exception { generateForAll( cfg, - ids, + writableSet, + writableSet, + "Type2TypeFunction.java", + "src/main/java/org/apache/giraph/function/primitive/func/%s2%sFunction.java"); + + generateForAll( + cfg, + mainIds, numerics, "Type2TypeMapEntryIterable.java", "src/main/java/org/apache/giraph/types/heaps/%s2%sMapEntryIterable.java"); generateForAll( cfg, - ids, + mainIds, numerics, "FixedCapacityType2TypeMinHeap.java", "src/main/java/org/apache/giraph/types/heaps/FixedCapacity%s%sMinHeap.java"); generateForAll( cfg, - ids, + mainIds, numerics, "TestFixedCapacityType2TypeMinHeap.java", "src/test/java/org/apache/giraph/types/heaps/TestFixedCapacity%s%sMinHeap.java"); diff --git a/giraph-core/src/test/java/org/apache/giraph/types/heaps/TestFixedCapacityIntShortMinHeap.java b/giraph-core/src/test/java/org/apache/giraph/types/heaps/TestFixedCapacityIntShortMinHeap.java new file mode 100644 index 000000000..8b01793f5 --- /dev/null +++ b/giraph-core/src/test/java/org/apache/giraph/types/heaps/TestFixedCapacityIntShortMinHeap.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.giraph.types.heaps; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +public class TestFixedCapacityIntShortMinHeap { + @Test + public void testHeap() { + int heapCapacity = 5; + FixedCapacityIntShortMinHeap heap = + new FixedCapacityIntShortMinHeap(heapCapacity); + int[] keys = new int[]{0, 1, 0, 10, 20, 0, 3, 4}; + short[] values = new short[]{ + 0, 1, 2, 2, 2, + 3, 3, 4}; + + List positions = new ArrayList<>(); + for (int i = 0; i < keys.length; i++) { + positions.add(i); + } + Collections.shuffle(positions); + for (Integer position : positions) { + heap.add(keys[position], values[position]); + } + + for (int i = keys.length - heapCapacity; i < keys.length; i++) { + Assert.assertEquals(heap.size(), heapCapacity); + Assert.assertEquals(heap.getMinKey(), keys[i]); + Assert.assertEquals(heap.getMinValue(), values[i]); + heap.removeMin(); + heapCapacity--; + } + Assert.assertTrue(heap.isEmpty()); + } +} diff --git a/giraph-core/src/test/java/org/apache/giraph/types/heaps/TestFixedCapacityLongShortMinHeap.java b/giraph-core/src/test/java/org/apache/giraph/types/heaps/TestFixedCapacityLongShortMinHeap.java new file mode 100644 index 000000000..b4a605f3c --- /dev/null +++ b/giraph-core/src/test/java/org/apache/giraph/types/heaps/TestFixedCapacityLongShortMinHeap.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.giraph.types.heaps; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +// AUTO-GENERATED class via class: +// org.apache.giraph.generate.GeneratePrimitiveClasses + +public class TestFixedCapacityLongShortMinHeap { + @Test + public void testHeap() { + int heapCapacity = 5; + FixedCapacityLongShortMinHeap heap = + new FixedCapacityLongShortMinHeap(heapCapacity); + long[] keys = new long[]{0, 1, 0, 10, 20, 0, 3, 4}; + short[] values = new short[]{ + 0, 1, 2, 2, 2, + 3, 3, 4}; + + List positions = new ArrayList<>(); + for (int i = 0; i < keys.length; i++) { + positions.add(i); + } + Collections.shuffle(positions); + for (Integer position : positions) { + heap.add(keys[position], values[position]); + } + + for (int i = keys.length - heapCapacity; i < keys.length; i++) { + Assert.assertEquals(heap.size(), heapCapacity); + Assert.assertEquals(heap.getMinKey(), keys[i]); + Assert.assertEquals(heap.getMinValue(), values[i]); + heap.removeMin(); + heapCapacity--; + } + Assert.assertTrue(heap.isEmpty()); + } +} diff --git a/giraph-core/templates/BasicType2ObjectOpenHashMap.java b/giraph-core/templates/BasicType2ObjectOpenHashMap.java new file mode 100644 index 000000000..a4f117d78 --- /dev/null +++ b/giraph-core/templates/BasicType2ObjectOpenHashMap.java @@ -0,0 +1,169 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.types.ops.collections.map; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.Collection; +import java.util.Iterator; + +import org.apache.giraph.types.ops.${type.camel}TypeOps; +import org.apache.giraph.types.ops.PrimitiveIdTypeOps; +import org.apache.giraph.types.ops.collections.Basic2ObjectMap; +import org.apache.giraph.types.ops.collections.WritableWriter; +import org.apache.giraph.types.ops.collections.Basic2ObjectMap.ReusableIterator; +import org.apache.hadoop.io.${type.camel}Writable; + +import com.google.common.base.Preconditions; + +import it.unimi.dsi.fastutil.${type.lower}s.${type.camel}2ObjectMap; +import it.unimi.dsi.fastutil.${type.lower}s.${type.camel}2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.${type.lower}s.${type.camel}Iterator; +import it.unimi.dsi.fastutil.${type.lower}s.${type.camel}2ObjectMap.Entry; +import it.unimi.dsi.fastutil.objects.ObjectIterator; + +/** + * ${type.camel}Writable implementation of Basic2ObjectMap. + * + * @param Value type + */ +public final class Basic${type.camel}2ObjectOpenHashMap + extends Basic2ObjectMap<${type.camel}Writable, V> { + /** Map */ + private final ${type.camel}2ObjectOpenHashMap map; + /** Value writer */ + private final WritableWriter valueWriter; + + /** + * Constructor + * + * @param valueWriter Writer of values + */ + public Basic${type.camel}2ObjectOpenHashMap(WritableWriter valueWriter) { + this.map = new ${type.camel}2ObjectOpenHashMap<>(); + this.valueWriter = valueWriter; + } + + /** + * Constructor + * + * @param capacity Capacity + * @param valueWriter Writer of values + */ + public Basic${type.camel}2ObjectOpenHashMap( + int capacity, WritableWriter valueWriter) { + this.map = new ${type.camel}2ObjectOpenHashMap<>(capacity); + this.valueWriter = valueWriter; + } + + @Override + public void clear() { + map.clear(); + } + + @Override + public int size() { + return map.size(); + } + + @Override + public boolean containsKey(${type.camel}Writable key) { + return map.containsKey(key.get()); + } + + @Override + public V put(${type.camel}Writable key, V value) { + return map.put(key.get(), value); + } + + @Override + public V get(${type.camel}Writable key) { + return map.get(key.get()); + } + + @Override + public V remove(${type.camel}Writable key) { + return map.remove(key.get()); + } + + @Override + public PrimitiveIdTypeOps<${type.camel}Writable> getKeyTypeOps() { + return ${type.camel}TypeOps.INSTANCE; + } + + @Override + public Iterator<${type.camel}Writable> fastKeyIterator() { + return new ReusableIterator<${type.camel}Iterator>(map.keySet().iterator()) { + @Override + public ${type.camel}Writable next() { + reusableKey.set(iter.next${type.camel}()); + return reusableKey; + } + + @Override + public void reset() { + iter = map.keySet().iterator(); + } + }; + } + + @Override + public Iterator valueIterator() { + return map.values().iterator(); + } + + @Override + public Collection values() { + return map.values(); + } + + @Override + public void write(DataOutput out) throws IOException { + Preconditions.checkState( + valueWriter != null, + "valueWriter is not provided" + ); + + out.writeInt(map.size()); + ObjectIterator<${type.camel}2ObjectMap.Entry> iterator = + map.${type.lower}2ObjectEntrySet().fastIterator(); + while (iterator.hasNext()) { + ${type.camel}2ObjectMap.Entry entry = iterator.next(); + out.write${type.camel}(entry.get${type.camel}Key()); + valueWriter.write(out, entry.getValue()); + } + } + + @Override + public void readFields(DataInput in) throws IOException { + Preconditions.checkState( + valueWriter != null, + "valueWriter is not provided" + ); + + int size = in.readInt(); + map.clear(); + map.trim(size); + while (size-- > 0) { + ${type.lower} key = in.read${type.camel}(); + V value = valueWriter.readFields(in); + map.put(key, value); + } + } +} diff --git a/giraph-core/templates/BasicTypeOpenHashSet.java b/giraph-core/templates/BasicTypeOpenHashSet.java new file mode 100644 index 000000000..2c9eca526 --- /dev/null +++ b/giraph-core/templates/BasicTypeOpenHashSet.java @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.giraph.types.ops.collections.set; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; + +import org.apache.giraph.types.ops.${type.camel}TypeOps; +import org.apache.giraph.types.ops.PrimitiveIdTypeOps; +import org.apache.giraph.types.ops.collections.BasicSet; +import org.apache.giraph.utils.Varint; +import org.apache.hadoop.io.${type.camel}Writable; + +import it.unimi.dsi.fastutil.${type.lower}s.${type.camel}Iterator; +<#if type.hasBigFastutil()> +import it.unimi.dsi.fastutil.${type.lower}s.${type.camel}OpenHashBigSet; + +import it.unimi.dsi.fastutil.${type.lower}s.${type.camel}OpenHashSet; +import it.unimi.dsi.fastutil.${type.lower}s.${type.camel}Set; + +${generated_message} + +/** ${type.camel}Writable implementation of BasicSet */ +public final class Basic${type.camel}OpenHashSet + implements BasicSet<${type.camel}Writable> { + /** Set */ + private final ${type.camel}Set set; + + /** Constructor */ + public Basic${type.camel}OpenHashSet() { + set = new ${type.camel}OpenHashSet(); + } + + /** + * Constructor + * + * @param capacity Capacity + */ +<#if type.hasBigFastutil()> + public Basic${type.camel}OpenHashSet(long capacity) { + if (capacity <= MAX_OPEN_HASHSET_CAPACITY) { + set = new ${type.camel}OpenHashSet((int) capacity); + } else { + set = new ${type.camel}OpenHashBigSet(capacity); + } + } +<#else> + public Basic${type.camel}OpenHashSet(int capacity) { + set = new ${type.camel}OpenHashSet(capacity); + } + + + @Override + public void clear() { + set.clear(); + } + + @Override + public long size() { +<#if type.hasBigFastutil()> + if (set instanceof ${type.camel}OpenHashBigSet) { + return ((${type.camel}OpenHashBigSet) set).size64(); + } + + return set.size(); + } + + @Override + public void trim(long n) { +<#if type.hasBigFastutil()> + if (set instanceof ${type.camel}OpenHashSet) { + ((${type.camel}OpenHashSet) set).trim((int) Math.max(set.size(), n)); + } else { + ((${type.camel}OpenHashBigSet) set).trim(Math.max(set.size(), n)); + } +<#else> + ((${type.camel}OpenHashSet) set).trim((int) Math.max(set.size(), n)); + + } + + @Override + public boolean add(${type.camel}Writable value) { + return set.add(value.get()); + } + + @Override + public boolean contains(${type.camel}Writable value) { + return set.contains(value.get()); + } + + @Override + public PrimitiveIdTypeOps<${type.camel}Writable> getElementTypeOps() { + return ${type.camel}TypeOps.INSTANCE; + } + + @Override + public void write(DataOutput out) throws IOException { +<#if type.hasBigFastutil()> + Varint.writeUnsignedVarLong(size(), out); +<#else> + Varint.writeUnsignedVarInt(set.size(), out); + + ${type.camel}Iterator iter = set.iterator(); + while (iter.hasNext()) { + out.write${type.camel}(iter.next${type.camel}()); + } + } + + @Override + public void readFields(DataInput in) throws IOException { +<#if type.hasBigFastutil()> + long size = Varint.readUnsignedVarLong(in); +<#else> + int size = Varint.readUnsignedVarInt(in); + + set.clear(); + trim(size); +<#if type.hasBigFastutil()> + for (long i = 0; i < size; ++i) { +<#else> + for (int i = 0; i < size; ++i) { + + set.add(in.read${type.camel}()); + } + } +} diff --git a/giraph-core/templates/FixedCapacityType2TypeMinHeap.java b/giraph-core/templates/FixedCapacityType2TypeMinHeap.java index 5dc37bcee..c6db995f0 100644 --- a/giraph-core/templates/FixedCapacityType2TypeMinHeap.java +++ b/giraph-core/templates/FixedCapacityType2TypeMinHeap.java @@ -31,7 +31,7 @@ import org.apache.giraph.function.primitive.pairs.${type1.camel}${type2.camel}Predicate; ${generated_message} -<#macro cast2><#if type2.lower == "byte">(${type2.lower}) +<#macro cast2><#if type2.opNeedCast>(${type2.lower}) /** * Min heap which holds (${type1.lower} key, ${type2.lower} value) pairs with diff --git a/giraph-core/templates/Type2TypeFunction.java b/giraph-core/templates/Type2TypeFunction.java index b35847022..f6d39e669 100644 --- a/giraph-core/templates/Type2TypeFunction.java +++ b/giraph-core/templates/Type2TypeFunction.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.giraph.function.primitive; +package org.apache.giraph.function.primitive.func; import java.io.Serializable; @@ -23,14 +23,14 @@ /** * Primitive specialization of Function: - * (${type.lower}) -> ${type.lower} + * (${type1.lower}) -> ${type2.lower} */ -public interface ${type.camel}2${type.camel}Function extends Serializable { +public interface ${type1.camel}2${type2.camel}Function extends Serializable { /** * Returns the result of applying this function to given {@code input}. * * @param input input * @return result */ - ${type.lower} apply(${type.lower} input); + ${type2.lower} apply(${type1.lower} input); } diff --git a/giraph-core/templates/Type2TypeMapEntryIterable.java b/giraph-core/templates/Type2TypeMapEntryIterable.java index 16b56e9ef..abfbbfe3d 100644 --- a/giraph-core/templates/Type2TypeMapEntryIterable.java +++ b/giraph-core/templates/Type2TypeMapEntryIterable.java @@ -18,7 +18,7 @@ package org.apache.giraph.types.heaps; -import it.unimi.dsi.fastutil.${type1.lower}s.${type1.camel}2${type2.camel}Map;; +import it.unimi.dsi.fastutil.${type1.lower}s.${type1.camel}2${type2.camel}Map; import it.unimi.dsi.fastutil.objects.ObjectIterable; import it.unimi.dsi.fastutil.objects.ObjectIterator; diff --git a/giraph-core/templates/TypeTypeOps.java b/giraph-core/templates/TypeTypeOps.java index bba752dd1..fa6ddfa63 100644 --- a/giraph-core/templates/TypeTypeOps.java +++ b/giraph-core/templates/TypeTypeOps.java @@ -17,12 +17,10 @@ */ package org.apache.giraph.types.ops; -<#if type.id> -import org.apache.giraph.types.ops.collections.Basic2ObjectMap.Basic${type.camel}2ObjectOpenHashMap; -import org.apache.giraph.types.ops.collections.BasicSet.Basic${type.camel}OpenHashSet; - import org.apache.giraph.types.ops.collections.array.W${type.camel}ArrayList; <#if type.id> +import org.apache.giraph.types.ops.collections.map.Basic${type.camel}2ObjectOpenHashMap; +import org.apache.giraph.types.ops.collections.set.Basic${type.camel}OpenHashSet; import org.apache.giraph.types.ops.collections.WritableWriter; import org.apache.hadoop.io.${type.camel}Writable; @@ -40,8 +38,8 @@ <#else> <#assign parent_type = "PrimitiveTypeOps<${type.camel}Writable>"> -<#macro cast_if_needed_v expr><#if type.lower == "byte">(${type.lower}) ${expr}<#else>${expr} -<#macro cast_if_needed_e expr><#if type.lower == "byte">(${type.lower}) (${expr})<#else>${expr} +<#macro cast_if_needed_v expr><#if type.opNeedCast>(${type.lower}) ${expr}<#else>${expr} +<#macro cast_if_needed_e expr><#if type.opNeedCast>(${type.lower}) (${expr})<#else>${expr} /** TypeOps implementation for working with ${type.camel}Writable type */ public enum ${type.camel}TypeOps implements @@ -92,7 +90,11 @@ public void set(${type.camel}Writable to, ${type.camel}Writable from) { @Override public Basic${type.camel}OpenHashSet createOpenHashSet(long capacity) { +<#if type.hasBigFastutil()> return new Basic${type.camel}OpenHashSet(capacity); +<#else> + return new Basic${type.camel}OpenHashSet((int) capacity); + } @Override diff --git a/giraph-core/templates/WTypeArrayList.java b/giraph-core/templates/WTypeArrayList.java index 8803ebd5f..2a942a438 100644 --- a/giraph-core/templates/WTypeArrayList.java +++ b/giraph-core/templates/WTypeArrayList.java @@ -34,7 +34,9 @@ import org.apache.giraph.utils.Varint; import it.unimi.dsi.fastutil.${type.lower}s.${type.camel}ArrayList; +<#if !type.numeric> import it.unimi.dsi.fastutil.${type.lower}s.${type.camel}Arrays; + import it.unimi.dsi.fastutil.${type.lower}s.${type.camel}Collection; import it.unimi.dsi.fastutil.${type.lower}s.${type.camel}List; @@ -160,6 +162,7 @@ public boolean fastForEachWhileW(Predicate<${type.camel}Writable> f) { * * @param f Function to call on each element. */ + @Override public void forEach${type.camel}(${type.camel}Consumer f) { for (int i = 0; i < size(); ++i) { f.apply(get${type.camel}(i)); @@ -174,6 +177,7 @@ public boolean fastForEachWhileW(Predicate<${type.camel}Writable> f) { * @return true if the predicate returned true for all elements, * false if it returned false for some element. */ + @Override public boolean forEachWhile${type.camel}(${type.camel}Predicate f) { for (int i = 0; i < size(); ++i) { if (!f.apply(get${type.camel}(i))) { @@ -185,7 +189,26 @@ public boolean fastForEachWhileW(Predicate<${type.camel}Writable> f) { @Override public void sort() { +<#if type.numeric> + Arrays.sort(elements(), 0, size()); + +<#if !type.numeric> ${type.camel}Arrays.quickSort(elements(), 0, size()); + + } + + @Override + public void swap(int i, int j) { + int size = size(); + if (i >= size || j >= size) { + throw new IndexOutOfBoundsException( + "Index (" + Math.max(i, j) + + ") is greater than or equal to list size (" + size + ")"); + } + ${type.lower}[] arr = elements(); + ${type.lower} tmp = arr[i]; + arr[i] = arr[j]; + arr[j] = tmp; } @Override