Summary: We add a naive model for `forEach` idiom for Java's Iterable and Maps. The model is naive because it doesn't take the cost of the lambda into account. This will be fixed later. Reviewed By: da319 Differential Revision: D23868203 fbshipit-source-id: 37d169c6fmaster
parent
43930deed5
commit
980f110156
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
class ForEachTest {
|
||||||
|
|
||||||
|
int add(Integer x, Integer y) {
|
||||||
|
return x + y;
|
||||||
|
}
|
||||||
|
|
||||||
|
int loop_linear(Integer x, List<Integer> list) {
|
||||||
|
int sum = 0;
|
||||||
|
for (Integer el : list) {
|
||||||
|
sum = +el + x;
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
void map_linear(Map<Integer, Integer> map) {
|
||||||
|
map.forEach((key, value) -> add(key, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
void list_linear(List<Integer> myList) {
|
||||||
|
myList.forEach(el -> add(el, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
// FN: We have limited lambda support and canot incur costs of the lambda calls yet.
|
||||||
|
void list_quadratic_FN(List<Integer> myList) {
|
||||||
|
myList.forEach(el -> loop_linear(el, myList));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue