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

org.dishevelled.matrix.Matrix1D Maven / Gradle / Ivy

The newest version!
/*

    dsh-matrix  long-addressable bit and typed object matrix implementations.
    Copyright (c) 2004-2012 held jointly by the individual authors.

    This library is free software; you can redistribute it and/or modify it
    under the terms of the GNU Lesser General Public License as published
    by the Free Software Foundation; either version 3 of the License, or (at
    your option) any later version.

    This library is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
    License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this library;  if not, write to the Free Software Foundation,
    Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.

    > http://www.fsf.org/licensing/licenses/lgpl.html
    > http://www.opensource.org/licenses/lgpl-license.php

*/
package org.dishevelled.matrix;

import java.util.Iterator;

import org.dishevelled.functor.UnaryFunction;
import org.dishevelled.functor.UnaryPredicate;
import org.dishevelled.functor.UnaryProcedure;
import org.dishevelled.functor.BinaryFunction;
import org.dishevelled.functor.BinaryPredicate;
import org.dishevelled.functor.BinaryProcedure;

/**
 * Typed fixed size matrix of objects in one dimension, indexed
 * by longs.
 *
 * @param  type of this 1D matrix
 * @author  Michael Heuer
 * @version $Revision: 1059 $ $Date: 2012-01-03 14:03:02 -0600 (Tue, 03 Jan 2012) $
 */
public interface Matrix1D
    extends Iterable
{

    /**
     * Return the size of this 1D matrix.
     *
     * @return the size of this 1D matrix
     */
    long size();

    /**
     * Return the cardinality of this 1D matrix, the number
     * of non-null values.
     *
     * @return the cardinality of this 1D matrix
     */
    long cardinality();

    /**
     * Return true if the cardinality of this 1D matrix is zero.
     *
     * @return true if the cardinality of this 1D matrix is zero
     */
    boolean isEmpty();

    /**
     * Clear all the values in this 1D matrix (optional operation).
     *
     * @throws UnsupportedOperationException if the clear operation
     *    is not supported by this 1D matrix
     */
    void clear();

    /**
     * Return the value at the specified index.
     *
     * @param index index, must be >= 0 and < size()
     * @return the value at the specified index
     * @throws IndexOutOfBoundsException if index is negative
     *    or if index is greater than or equal to size()
     */
    E get(long index);

    /**
     * Return the value at the specified index without checking bounds.
     *
     * @param index index, should be >= 0 and < size()
     *    (unchecked)
     * @return the value at the specified index without checking bounds
     */
    E getQuick(long index);

    /**
     * Set the value at the specified index to e (optional operation).
     *
     * @param index index, must be >= 0 and < size()
     * @param e value
     * @throws IndexOutOfBoundsException if index is negative
     *    or if index is greater than or equal to size()
     * @throws UnsupportedOperationException if the set operation
     *    is not supported by this 1D matrix
     */
    void set(long index, E e);

    /**
     * Set the value at the specified index to e without
     * checking bounds (optional operation).
     *
     * @param index index, should be >= 0 and < size()
     *    (unchecked)
     * @param e value
     * @throws UnsupportedOperationException if the setQuick operation
     *    is not supported by this 1D matrix
     */
    void setQuick(long index, E e);

    /**
     * Return an iterator over the values in this 1D matrix, including
     * nulls.
     *
     * @return an iterator over the values in this 1D matrix, including
     *    nulls
     */
    Iterator iterator();

    /**
     * Assign all values in this 1D matrix to e (optional operation).
     *
     * @param e value
     * @return this 1D matrix, for convenience
     * @throws UnsupportedOperationException if this assign operation
     *    is not supported by this 1D matrix
     */
    Matrix1D assign(E e);

    /**
     * Assign the result of the specified function to each value
     * in this 1D matrix (optional operation).
     *
     * @param function function, must not be null
     * @return this 1D matrix, for convenience
     * @throws UnsupportedOperationException if this assign operation
     *    is not supported by this 1D matrix
     */
    Matrix1D assign(UnaryFunction function);

    /**
     * Assign all values in this 1D matrix to the values in the
     * specified matrix (optional operation).
     *
     * @param other other 1D matrix, must not be null and must
     *    be the same size as this 1D matrix
     * @return this 1D matrix, for convenience
     * @throws UnsupportedOperationException if this assign operation
     *    is not supported by this 1D matrix
     */
    Matrix1D assign(Matrix1D other);

    /**
     * Assign the result of the specified function of a value from
     * this 1D matrix and the specified matrix to each value in this
     * 1D matrix (optional operation).
     *
     * @param other other 1D matrix, must not be null and must
     *    be the same size as this 1D matrix
     * @param function function, must not be null
     * @return this 1D matrix, for convenience
     * @throws UnsupportedOperationException if this assign operation
     *    is not supported by this 1D matrix
     */
    Matrix1D assign(Matrix1D other,
                             BinaryFunction function);

    /**
     * Apply a function to each value in this 1D matrix and aggregate
     * the result.
     *
     * @param aggr aggregate function, must not be null
     * @param function function, must not be null
     * @return the aggregate result
     */
    E aggregate(BinaryFunction aggr, UnaryFunction function);

    /**
     * Apply a function to each value in this 1D matrix and the specified
     * matrix and aggregate the result.
     *
     * @param other other 1D matrix, must not be null and must
     *    be the same size as this 1D matrix
     * @param aggr aggregate function, must not be null
     * @param function function, must not be null
     * @return the aggregate result
     */
    E aggregate(Matrix1D other,
                BinaryFunction aggr,
                BinaryFunction function);

    /**
     * Return a new 1D matrix flip view.  What used to be index
     * 0 is now index size() - 1, ..., what used to
     * be index size() - 1 is now index 0.  The
     * view is backed by this matrix, so changes made to the returned view
     * are reflected in this matrix, and vice-versa.
     *
     * @return a new 1D matrix flip view
     */
    Matrix1D viewFlip();

    /**
     * Return a new 1D matrix sub-range view that contains only those values
     * from index index to index + width - 1.
     * The view is backed by this matrix, so changes made to the returned
     * view are reflected in this matrix, and vice-versa.
     *
     * @param index index, must be >= 0 and < size()
     * @param width width
     * @return a new 1D matrix sub-range view that contains only those values
     *    from index index to index + width - 1
     */
    Matrix1D viewPart(long index, long width);

    /**
     * Return a new 1D matrix selection view that contains only those values
     * at the specified indices.  The view is backed by this matrix, so
     * changes made to the returned view are reflected in this matrix,
     * and vice-versa.
     *
     * @param indices indices
     * @return a new 1D matrix selection view that contains only those values
     *    at the specified indices
     */
    Matrix1D viewSelection(long[] indices);

    /**
     * Return a new 1D matrix selection view that contains only those values
     * selected by the specified predicate.  The view is backed by this
     * matrix, so changes made to the returned view are reflected in
     * this matrix, and vice-versa.
     *
     * @param predicate predicate, must not be null
     * @return a new 1D matrix selection view that contains only those values
     *    selected by the specified predicate
     */
    Matrix1D viewSelection(UnaryPredicate predicate);

    /**
     * Return a new 1D matrix selection view that contains only those values
     * at the indices present in the specified bit mask.  The view is backed by this matrix, so
     * changes made to the returned view are reflected in this matrix, and vice-versa.
     *
     * @param mask 1D bit mask, must not be null
     * @return a new 1D matrix selection view that contains only those values
     *    at the indices present in the specified mask
     */
    Matrix1D viewSelection(BitMatrix1D mask);

    /**
     * Return a new 1D matrix stride view which is a sub matrix
     * consisting of every i-th value in this matrix.  The view is backed
     * by this matrix, so changes made to the returned view are reflected in
     * this matrix, and vice-versa.
     *
     * @param stride stride, must be > 0
     * @return a new 1D matrix stride view which is a sub matrix consisting
     *    of every i-th value in this matrix
     * @throws IndexOutOfBoundsException if stride is
     *    negative or zero
     */
    Matrix1D viewStrides(long stride);

    /**
     * Apply the specified procedure to each value in this 1D matrix.
     *
     * 

For example: *

     * Matrix1D<String> m;
     * m.forEach(new UnaryProcedure<String>()
     *     {
     *         public void run(final String value)
     *         {
     *             System.out.println(value);
     *         }
     *     });
     * 

* * @param procedure procedure, must not be null */ void forEach(UnaryProcedure procedure); /** * Apply the specified procedure to each value in this 1D matrix * accepted by the specified predicate. * *

For example: *

     * Matrix1D<String> m;
     * m.forEach(new UnaryPredicate<String>()
     *     {
     *         public boolean test(final String value)
     *         {
     *             return (value != null);
     *         }
     *     }, new UnaryProcedure<String>()
     *     {
     *         public void run(final String value)
     *         {
     *             System.out.println(value);
     *         }
     *     });
     * 

* * @param predicate predicate, must not be null * @param procedure procedure, must not be null */ void forEach(UnaryPredicate predicate, UnaryProcedure procedure); /** * Apply the specified procedure to each non-null value in this 1D matrix. * *

For example: *

     * Matrix1D<String> m;
     * m.forEachNonNull(new UnaryProcedure<String>()
     *     {
     *         public void run(final String value)
     *         {
     *             System.out.println(value);
     *         }
     *     });
     * 

* * @param procedure procedure, must not be null */ void forEachNonNull(UnaryProcedure procedure); /** * Apply the specified procedures to each index and value in this * 1D matrix. * *

For example: *

     * Matrix1D<String> m;
     * m.forEach(new BinaryProcedure<Long, String>()
     *     {
     *         public void run(final Long index, final String value)
     *         {
     *             System.out.print("m[" + index + "]=" + value);
     *         }
     *     });
     * 

* * @param procedure procedure, must not be null */ void forEach(BinaryProcedure procedure); /** * Apply the specified procedures to each index and value in this * 1D matrix accepted by the specified predicate. * *

For example: *

     * Matrix1D<String> m;
     * m.forEach(new BinaryPredicate<Long, String>()
     *     {
     *         public boolean test(final Long index, final String value)
     *         {
     *             return (value != null);
     *         }
     *     }, new BinaryProcedure<Long, String>()
     *     {
     *         public void run(final Long index, final String value)
     *         {
     *             System.out.print("m[" + index + "]=" + value);
     *         }
     *     });
     * 

* * @param predicate predicate, must not be null * @param procedure procedure, must not be null */ void forEach(BinaryPredicate predicate, BinaryProcedure procedure); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy