001/*-
002 * Copyright 2016 Diamond Light Source Ltd.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 */
009
010package org.eclipse.january.dataset;
011
012/**
013 * Class to run over a pair of contiguous datasets with only the second dataset read
014 */
015public class ContiguousSingleIterator extends BroadcastSelfIterator {
016        private final int aMax; // maximum index in array
017        private final int aStep; // step over items
018        private final int bMax; // maximum index in array
019        private final int bStep;
020
021        public ContiguousSingleIterator(Dataset a, Dataset b) {
022                super(a, b);
023                aStep = a.getElementsPerItem();
024                aMax = a.getSize() * aStep;
025                bStep = b.getElementsPerItem();
026                bMax = b.getSize() * bStep;
027                maxShape = a.getShape();
028                asDouble = aDataset.hasFloatingPointElements();
029                reset();
030        }
031
032        @Override
033        public boolean hasNext() {
034                aIndex += aStep;
035                bIndex += bStep;
036
037                if (aIndex >= aMax || bIndex >= bMax) {
038                        return false;
039                }
040                if (read) {
041                        if (asDouble) {
042                                bDouble = bDataset.getElementDoubleAbs(bIndex);
043                        } else {
044                                bLong = bDataset.getElementLongAbs(bIndex);
045                        }
046                }
047                return true;
048        }
049
050        @Override
051        public int[] getPos() {
052                return null;
053        }
054
055        @Override
056        public void reset() {
057                aIndex = -aStep;
058                bIndex = -bStep;
059                if (read) {
060                        storeCurrentValues();
061                }
062        }
063}