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

com.swirlds.common.test.set.RandomAccessSet Maven / Gradle / Ivy

Go to download

Swirlds is a software platform designed to build fully-distributed applications that harness the power of the cloud without servers. Now you can develop applications with fairness in decision making, speed, trust and reliability, at a fraction of the cost of traditional server-based platforms.

There is a newer version: 0.46.3
Show newest version
/*
 * Copyright (C) 2020-2023 Hedera Hashgraph, LLC
 *
 * 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.swirlds.common.test.set;

import java.util.Collection;
import java.util.Random;
import java.util.Set;

/**
 * A set that supports efficient access of random elements.
 *
 * @param 
 */
public interface RandomAccessSet extends Set {

    /**
     * Get a random element. Element is chosen with even probability of selecting any element in the set.
     * O(1) time.
     *
     * @param random
     * 		a source of randomness
     * @return a randomly chosen element
     * @throws java.util.NoSuchElementException
     * 		if the set is empty
     */
    T get(Random random);

    /**
     * Get an element at a given index. Element returned is guaranteed to be deterministic. Mutating the set
     * in any way may cause a different element to be returned for the same index. O(1) time.
     *
     * @param index
     * 		the index of the element to return
     * @return the element that corresponds to the given index
     */
    T get(int index);

    /**
     * {@inheritDoc}
     */
    @Override
    default boolean containsAll(final Collection c) {
        throw new UnsupportedOperationException();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    default boolean addAll(final Collection c) {
        throw new UnsupportedOperationException();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    default boolean retainAll(final Collection c) {
        throw new UnsupportedOperationException();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    default boolean removeAll(final Collection c) {
        throw new UnsupportedOperationException();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy