internal Tuple <T, R> NextInternal() { object tObj = range.MoveNext() ? (object)iter[range.Current] : null; Tuple <T, R> ret = next; next = tObj != null ? new Tuple <T, R>((T)tObj, fn((T)tObj)) : null; return(ret); }
/** * Constructs a new {@code GroupBy} * * @param l the {@link List} containing the items used as input to the * key generating function. * @param fn the {@link Function} to be used to generate the keys which describe * the like contents of each grouping. */ public GroupBy(List <T> l, Func <T, R> fn) { this.iter = l; this.fn = fn; this.range = IntGenerator.Of(0, iter.Count); if (range.MoveNext()) { T t = iter[range.Current]; //next = new Pair<T, R>(t, fn.apply(t)); //T t = (T) Convert.ChangeType(range.Current, typeof(T)); next = new Tuple <T, R>(t, fn(t)); } }
/** * Like {@link #neighborhood(int, int)}, except that the neighborhood isn't truncated when it's * near an edge. It wraps around to the other side. * * @param centerIndex The index of the point. The coordinates are expressed as a single index by * using the dimensions as a mixed radix definition. For example, in dimensions * 42x10, the point [1, 4] is index 1*420 + 4*10 = 460. * @param radius The radius of this neighborhood about the centerIndex. * @return The points in the neighborhood, including centerIndex. */ public int[] WrappingNeighborhood(int centerIndex, int radius) { int[] cp = CoordinatesFromIndex(centerIndex); IntGenerator[] igs = ArrayUtils.Range(0, dimensions.Length) .Select(i => new IntGenerator(cp[i] - radius, Math.Min((cp[i] - radius) + dimensions[i] - 1, cp[i] + radius) + 1)) .ToArray();//IntGenerator[]::new List <List <int> > result = new List <List <int> >(); result.Add(new List <int>()); List <List <int> > interim = new List <List <int> >(); for (int i = 0; i < igs.Length; i++) { IntGenerator pool = igs[i]; int size = result.Count; interim.Clear(); interim.AddRange(result); result.Clear(); for (int x = 0; x < size; x++) { List <int> lx = interim[x]; pool.Reset(); for (int y = 0; y < pool.Count; y++) { pool.MoveNext(); int py = ArrayUtils.Modulo(pool.Current, dimensions[i]); List <int> tl = new List <int>(); tl.AddRange(lx); tl.Add(py); result.Add(tl); } } } return(result.AsParallel().Select(tl => IndexFromCoordinates(tl.ToArray())).ToArray()); }