aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-01-21 16:39:54 +0100
committerMattias Andrée <maandree@operamail.com>2014-01-21 16:39:54 +0100
commit0a30c3ab8f4aaab3aca7d43ca889f18e693a5222 (patch)
tree544ad28c37941eb442a9251a45cad52fdeed2102 /src
parentpartial array support in binary search + add multibinary search (diff)
downloadalgorithms-and-data-structures-0a30c3ab8f4aaab3aca7d43ca889f18e693a5222.tar.gz
algorithms-and-data-structures-0a30c3ab8f4aaab3aca7d43ca889f18e693a5222.tar.bz2
algorithms-and-data-structures-0a30c3ab8f4aaab3aca7d43ca889f18e693a5222.tar.xz
partial array support in interpolation search
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
-rw-r--r--src/algorithms/searching/InterpolationSearch.java66
1 files changed, 62 insertions, 4 deletions
diff --git a/src/algorithms/searching/InterpolationSearch.java b/src/algorithms/searching/InterpolationSearch.java
index 1e4aaa8..63bfd17 100644
--- a/src/algorithms/searching/InterpolationSearch.java
+++ b/src/algorithms/searching/InterpolationSearch.java
@@ -42,9 +42,38 @@ public class InterpolationSearch
*/
public static int indexOf(£{T} item, £{T}[] array)
{
+ return indexOf(item, array, 0, array.length);
+ }
+
+ /**
+ * Find the easiest to find occurance of an item in a list
+ *
+ * @param item The item to find
+ * @param array The list in which to search
+ * @param start The index of the first position to search in the array
+ * @return The index of the easiest to find occurance of the item. The bitwise
+ * negation of the position it insert it in is returned if it was not found.
+ */
+ public static int indexOf(£{T} item, £{T}[] array, int start)
+ {
+ return indexOf(item, array, start, array.length);
+ }
+
+ /**
+ * Find the easiest to find occurance of an item in a list
+ *
+ * @param item The item to find
+ * @param array The list in which to search
+ * @param start The index of the first position to search in the array
+ * @param end The index after the last position to search in the array
+ * @return The index of the easiest to find occurance of the item. The bitwise
+ * negation of the position it insert it in is returned if it was not found.
+ */
+ public static int indexOf(£{T} item, £{T}[] array, int start, int end)
+ {
£{T} low, high, at;
- int min = 0, mid;
- int max = array.length - 1;
+ int min = start, mid;
+ int max = end - 1;
for (;;)
{
@@ -74,9 +103,38 @@ public class InterpolationSearch
*/
public static int indexOf(£{T} item, £{T}[] array)
{
+ return indexOf(item, array, 0, array.length);
+ }
+
+ /**
+ * Find the easiest to find occurance of an item in a list
+ *
+ * @param item The item to find
+ * @param array The list in which to search
+ * @param start The index of the first position to search in the array
+ * @return The index of the easiest to find occurance of the item. The bitwise
+ * negation of the position it insert it in is returned if it was not found.
+ */
+ public static int indexOf(£{T} item, £{T}[] array, int start)
+ {
+ return indexOf(item, array, start, array.length);
+ }
+
+ /**
+ * Find the easiest to find occurance of an item in a list
+ *
+ * @param item The item to find
+ * @param array The list in which to search
+ * @param start The index of the first position to search in the array
+ * @param end The index after the last position to search in the array
+ * @return The index of the easiest to find occurance of the item. The bitwise
+ * negation of the position it insert it in is returned if it was not found.
+ */
+ public static int indexOf(£{T} item, £{T}[] array, int start, int end)
+ {
£{T} low, high, at;
- int min = 0, mid;
- int max = array.length - 1;
+ int min = start, mid;
+ int max = end - 1;
for (;;)
{