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

com.epam.deltix.util.collections.generated.HdDateTimeHashSet Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2021 EPAM Systems, Inc
 *
 * See the NOTICE file distributed with this work for additional information
 * regarding copyright ownership. Licensed 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 com.epam.deltix.util.collections.generated;

import com.epam.deltix.util.collections.hash.*;
import com.epam.deltix.util.collections.*;
import java.io.*;
import java.util.*;
import com.epam.deltix.hdtime.HdDateTime;

@SuppressWarnings ("unchecked")
public class HdDateTimeHashSet extends HdDateTimeHashMapBase
{
    public HdDateTimeHashSet () {
        super ();
    }

    public HdDateTimeHashSet (int cap) {
        super (cap);
    }

    public HdDateTimeHashSet (HashCodeComputer hashCodeComputer) {
        super (0, hashCodeComputer);
    }

    public HdDateTimeHashSet (int cap, HashCodeComputer hashCodeComputer) {
        super (cap, hashCodeComputer);
    }

    public HdDateTimeHashSet (HdDateTime[] values) {
        super ();

        for (int i = 0; values != null && i < values.length; i++)
            add(values[i]);
    }

    protected void              resizeTable (int newSize) {
        final int                   curLength = keys.length;
        final HdDateTime []            saveKeys = keys;
        final int []                savePrev = prev;

        allocTable (newSize);

        for (int ii = 0; ii < curLength; ii++)
            if (savePrev [ii] != NULL)
                putNewNoSpaceCheck (saveKeys [ii]);
    }

    private void                putNewNoSpaceCheck (HdDateTime key) {
        int         hidx = hashIndex (key);
        int         idx = find (hidx, key);

        if (idx != NULL)
            throw new IllegalArgumentException (
                "Key " + key + " already exists"
            );

        idx = allocEntry (hidx);

        keys [idx] = key;
    }

    public final boolean        contains (HdDateTime key) {
    	return (containsKey (key));
    }

    public boolean              add (HdDateTime key) {
        int         hidx = hashIndex (key);
        int         idx = find (hidx, key);

        if (idx != NULL)
            return (false);

        if (freeHead == NULL) {
            resizeTable (keys.length * 2);
            hidx = hashIndex (key); // recompute!
        }

        idx = allocEntry (hidx);

        putKey (idx, key);

        return (true);
    }

    @Override
    public final boolean        equals (Object o) {
        throw new UnsupportedOperationException ();
    }

    @Override
    public int                  hashCode () {
        throw new UnsupportedOperationException ();
    }

    public final HdDateTime []       toArray (HdDateTime [] reuse) {
        return (keysToArray (reuse));
    }


    static final long           serialVersionUID = 1L;

    private void                writeObject (ObjectOutputStream out)
        throws IOException
    {
        out.writeShort (1);
        out.writeInt (size ());

        final int       tabSize = keys.length;
        int             numWritten = 0;

        for (int ii = 0; ii < tabSize; ii++) {
            if (isFilled (ii)) {
                numWritten++;
 				out.writeLong (HdDateTime.toUnderlying(keys [ii]));
            }
        }

        if (numWritten != size ())
            throw new RuntimeException (
                "Size mismatch: " + numWritten + " instead of " + size ()
            );
    }

    private void                readObject (ObjectInputStream in)
        throws IOException, ClassNotFoundException
    {
    	@SuppressWarnings("unused")
        short           readSerialVersion = in.readShort();

        int             inCount = in.readInt ();

        allocTable (inCount);

        for (int ii = 0; ii < inCount; ii++) {
            HdDateTime       key = HdDateTime.fromUnderlying(in.readLong ());

            add (key);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy