All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.deephaven.engine.table.impl.by.ssmcountdistinct.CharSsmBackedSource Maven / Gradle / Ivy

There is a newer version: 0.37.1
Show newest version
/**
 * Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
 */
package io.deephaven.engine.table.impl.by.ssmcountdistinct;

import io.deephaven.vector.CharVector;
import io.deephaven.engine.table.impl.AbstractColumnSource;
import io.deephaven.engine.table.impl.ColumnSourceGetDefaults;
import io.deephaven.engine.table.impl.MutableColumnSourceGetDefaults;
import io.deephaven.engine.table.impl.sources.ObjectArraySource;
import io.deephaven.engine.table.impl.ssms.CharSegmentedSortedMultiset;
import io.deephaven.engine.rowset.RowSet;

/**
 * A {@link SsmBackedColumnSource} for Characters.
 */
public class CharSsmBackedSource extends AbstractColumnSource
                                 implements ColumnSourceGetDefaults.ForObject,
                                            MutableColumnSourceGetDefaults.ForObject,
                                            SsmBackedColumnSource {
    private final ObjectArraySource underlying;
    private boolean trackingPrevious = false;

    //region Constructor
    public CharSsmBackedSource() {
        super(CharVector.class, char.class);
        underlying = new ObjectArraySource<>(CharSegmentedSortedMultiset.class, char.class);
    }
    //endregion Constructor

    //region SsmBackedColumnSource
    @Override
    public CharSegmentedSortedMultiset getOrCreate(long key) {
        CharSegmentedSortedMultiset ssm = underlying.getUnsafe(key);
        if(ssm == null) {
            //region CreateNew
            underlying.set(key, ssm = new CharSegmentedSortedMultiset(SsmDistinctContext.NODE_SIZE));
            //endregion CreateNew
        }
        ssm.setTrackDeltas(trackingPrevious);
        return ssm;
    }

    @Override
    public CharSegmentedSortedMultiset getCurrentSsm(long key) {
        return underlying.getUnsafe(key);
    }

    @Override
    public void clear(long key) {
        underlying.set(key, null);
    }

    @Override
    public void ensureCapacity(long capacity) {
        underlying.ensureCapacity(capacity);
    }

    @Override
    public ObjectArraySource getUnderlyingSource() {
        return underlying;
    }
    //endregion

    @Override
    public boolean isImmutable() {
        return false;
    }

    @Override
    public CharVector get(long rowKey) {
        return underlying.get(rowKey);
    }

    @Override
    public CharVector getPrev(long rowKey) {
        final CharSegmentedSortedMultiset maybePrev = underlying.getPrev(rowKey);
        return maybePrev == null ? null : maybePrev.getPrevValues();
    }

    @Override
    public void startTrackingPrevValues() {
        trackingPrevious = true;
        underlying.startTrackingPrevValues();
    }

    @Override
    public void clearDeltas(RowSet indices) {
        indices.iterator().forEachLong(key -> {
            final CharSegmentedSortedMultiset ssm = getCurrentSsm(key);
            if(ssm != null) {
                ssm.clearDeltas();
            }
            return true;
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy