summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalList.java
diff options
context:
space:
mode:
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalList.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalList.java47
1 files changed, 44 insertions, 3 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalList.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalList.java
index a017aa9..949fc33 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalList.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IFunctionalList.java
@@ -1,20 +1,22 @@
package bjc.utils.funcdata;
import java.util.Comparator;
-import java.util.Random;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
-import bjc.utils.data.IPair;
+import bjc.utils.data.experimental.IPair;
/**
* A wrapper over another list that provides eager functional operations
* over it. Differs from a stream in every way except for the fact that
* they both provide functional operations.
*
+ * NOTE: The indications of complexity for methods assume that the backing
+ * list has performance on the order of an array
+ *
* @author ben
*
* @param <E>
@@ -25,6 +27,8 @@ public interface IFunctionalList<E> {
/**
* Add an item to this list
*
+ * Takes O(1) time.
+ *
* @param item
* The item to add to this list.
* @return Whether the item was added to the list succesfully.
@@ -35,6 +39,10 @@ public interface IFunctionalList<E> {
* Check if all of the elements of this list match the specified
* predicate.
*
+ * Takes O(f * p(n)) time on average, where f is defined as the average
+ * number of elements in a list until the predicate returns false, and
+ * p is the average running time of the predicate
+ *
* @param matchPredicate
* The predicate to use for checking.
* @return Whether all of the elements of the list match the specified
@@ -45,6 +53,10 @@ public interface IFunctionalList<E> {
/**
* Check if any of the elements in this list match the specified list.
*
+ * Takes O(f * p(n)) time on average, where f is defined as the average
+ * number of elements in a list until the predicate returns true, and p
+ * is the average running time of the predicate
+ *
* @param matchPredicate
* The predicate to use for checking.
* @return Whether any element in the list matches the provided
@@ -60,6 +72,10 @@ public interface IFunctionalList<E> {
* NOTE: The returned list will have the length of the shorter of this
* list and the combined one.
*
+ * Takes O(q * c(q)), where q is defined as the length of the shorter
+ * of this list and the provided one, and c is the running time of the
+ * combiner.
+ *
* @param <T>
* The type of the second list
* @param <F>
@@ -77,6 +93,8 @@ public interface IFunctionalList<E> {
/**
* Check if the list contains the specified item
*
+ * Takes O(n) time, assuming object compare in constant time.
+ *
* @param item
* The item to see if it is contained
* @return Whether or not the specified item is in the list
@@ -86,6 +104,8 @@ public interface IFunctionalList<E> {
/**
* Get the first element in the list
*
+ * Takes O(1) time
+ *
* @return The first element in this list.
*/
E first();
@@ -94,6 +114,9 @@ public interface IFunctionalList<E> {
* Apply a function to each member of the list, then flatten the
* results. Does not change the underlying list.
*
+ * Takes O(n * m) time, where m is the average number of elements in
+ * the returned list.
+ *
* @param <T>
* The type of the flattened list
*
@@ -108,6 +131,9 @@ public interface IFunctionalList<E> {
/**
* Apply a given action for each member of the list
*
+ * Takes O(n * f(n)) time, where n is the length of the list, and f is
+ * the running time of the action.
+ *
* @param action
* The action to apply to each member of the list.
*/
@@ -116,6 +142,9 @@ public interface IFunctionalList<E> {
/**
* Apply a given function to each element in the list and its index.
*
+ * Takes O(n * f(n)) time, where n is the length of the list, and f is
+ * the running time of the action.
+ *
* @param indexedAction
* The function to apply to each element in the list and its
* index.
@@ -125,6 +154,8 @@ public interface IFunctionalList<E> {
/**
* Retrieve a value in the list by its index.
*
+ * Takes O(1) time.
+ *
* @param index
* The index to retrieve a value from.
* @return The value at the specified index in the list.
@@ -134,6 +165,7 @@ public interface IFunctionalList<E> {
/**
* Retrieve a list containing all elements matching a predicate
*
+ * Takes O(n) time, where n is the number of elements in the list
* @param matchPredicate
* The predicate to match by
* @return A list containing all elements that match the predicate
@@ -206,7 +238,7 @@ public interface IFunctionalList<E> {
* The random number generator to use.
* @return A random element from this list.
*/
- E randItem(Random rnd);
+ E randItem(Function<Integer, Integer> rnd);
/**
* Reduce this list to a single value, using a accumulative approach.
@@ -278,4 +310,13 @@ public interface IFunctionalList<E> {
* @return An iterable view onto the list
*/
Iterable<E> toIterable();
+
+ /**
+ * Convert this list into an array
+ *
+ * @param arrType
+ * The type of array to return
+ * @return The list, as an array
+ */
+ E[] toArray(E[] arrType);
} \ No newline at end of file