Class ArraysAlgos


  • public class ArraysAlgos
    extends java.lang.Object
    This class provides a set of basic methods that can be used with itemsets represented as arrays of integers. All the methods are static methods so that they can be used in any classes.
    Author:
    Philippe Fournier-Viger
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.Comparator<int[]> comparatorItemsetSameSize
      A Comparator for comparing two itemsets having the same size using the lexical order.
    • Constructor Summary

      Constructors 
      Constructor Description
      ArraysAlgos()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean allTheSameExceptLastItem​(int[] itemset1, int[] itemset2)
      This method checks if this itemset is the same as another itemset except for the last item.
      static int[] appendIntegerToArray​(int[] array, int integer)
      Append an integer at the end of an array of integers.
      static int[] cloneItemSetMinusAnItemset​(int[] itemset, int[] itemsetToNotKeep)
      Make a copy of this itemset but exclude a set of items
      static int[] cloneItemSetMinusOneItem​(int[] itemset, java.lang.Integer itemToRemove)
      Make a copy of this itemset but exclude a given item
      static int[] concatenate​(int[] prefix, int[] suffix)
      Method to concatenate two arrays in a new array
      static boolean contains​(int[] itemset, int item)
      Check if an a sorted list of integers contains an integer.
      static boolean containsLEX​(int[] itemset, int item)
      This method checks if the item "item" is in the itemset.
      static boolean containsLEX​(java.lang.Integer[] itemset, java.lang.Integer item, int maxItemInArray)
      This method checks if an item "item" is in the itemset "itemset".
      static boolean containsLEXPlus​(int[] itemset, int item)
      This method checks if the item "item" is in the itemset.
      static boolean containsOrEquals​(java.lang.Integer[] itemset1, java.lang.Integer[] itemset2)
      Check if an itemset contains another itemset.
      static double[] convertStringArrayToDoubleArray​(java.lang.String[] tokens)
      Convert a string array to a double array
      static boolean includedIn​(int[] itemset1, int[] itemset2)
      Check if a sorted itemset is contained in another
      static boolean includedIn​(int[] itemset1, int itemset1Length, int[] itemset2)
      Check if a sorted itemset is contained in another
      static int[] intersectTwoSortedArrays​(int[] array1, int[] array2)
      This method performs the intersection of two sorted arrays of integers and return a new sorted array.
      static int sameAs​(int[] itemset1, int[] itemsets2, int posRemoved)
      Method to compare two sorted list of integers and see if they are the same, while ignoring an item from the second list of integer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • comparatorItemsetSameSize

        public static java.util.Comparator<int[]> comparatorItemsetSameSize
        A Comparator for comparing two itemsets having the same size using the lexical order.
    • Constructor Detail

      • ArraysAlgos

        public ArraysAlgos()
    • Method Detail

      • cloneItemSetMinusOneItem

        public static int[] cloneItemSetMinusOneItem​(int[] itemset,
                                                     java.lang.Integer itemToRemove)
        Make a copy of this itemset but exclude a given item
        Parameters:
        itemToRemove - the given item
        Returns:
        the copy
      • cloneItemSetMinusAnItemset

        public static int[] cloneItemSetMinusAnItemset​(int[] itemset,
                                                       int[] itemsetToNotKeep)
        Make a copy of this itemset but exclude a set of items
        Parameters:
        itemsetToNotKeep - the set of items to be excluded
        Returns:
        the copy
      • allTheSameExceptLastItem

        public static boolean allTheSameExceptLastItem​(int[] itemset1,
                                                       int[] itemset2)
        This method checks if this itemset is the same as another itemset except for the last item. It assumes that both itemsets have the same length.
        Parameters:
        itemset1 - the first itemset
        itemset2 - the second itemset
        Returns:
        true if they are the same except for the last item
      • concatenate

        public static int[] concatenate​(int[] prefix,
                                        int[] suffix)
        Method to concatenate two arrays in a new array
        Parameters:
        prefix - the first array
        suffix - the second array
        Returns:
        the resulting array
      • intersectTwoSortedArrays

        public static int[] intersectTwoSortedArrays​(int[] array1,
                                                     int[] array2)
        This method performs the intersection of two sorted arrays of integers and return a new sorted array.
        Parameters:
        a - the first array
        b - the second array
        Returns:
        the resulting sorted array
      • containsOrEquals

        public static boolean containsOrEquals​(java.lang.Integer[] itemset1,
                                               java.lang.Integer[] itemset2)
        Check if an itemset contains another itemset. It assumes that itemsets are sorted according to the lexical order.
        Parameters:
        itemset1 - the first itemset
        itemset2 - the second itemset
        Returns:
        true if the first itemset contains the second itemset
      • containsLEX

        public static boolean containsLEX​(java.lang.Integer[] itemset,
                                          java.lang.Integer item,
                                          int maxItemInArray)
        This method checks if an item "item" is in the itemset "itemset". It assumes that items in the itemset are sorted in lexical order and that the largest item in the itemset is known.
        Parameters:
        itemset - an itemset
        item - the item
        maxItemInArray - the largest item in the itemset
        Returns:
        returnt true if the item appears in the itemset
      • sameAs

        public static int sameAs​(int[] itemset1,
                                 int[] itemsets2,
                                 int posRemoved)
        Method to compare two sorted list of integers and see if they are the same, while ignoring an item from the second list of integer. This methods is used by some Apriori algorithms.
        Parameters:
        itemset1 - the first itemset
        itemsets2 - the second itemset
        posRemoved - the position of an item that should be ignored from "itemset2" to perform the comparison.
        Returns:
        0 if they are the same, 1 if itemset is larger according to lexical order, -1 if smaller.
      • includedIn

        public static boolean includedIn​(int[] itemset1,
                                         int[] itemset2)
        Check if a sorted itemset is contained in another
        Parameters:
        itemset1 - the first itemset
        itemset2 - the second itemset
        Returns:
        true if yes, otherwise false
      • includedIn

        public static boolean includedIn​(int[] itemset1,
                                         int itemset1Length,
                                         int[] itemset2)
        Check if a sorted itemset is contained in another
        Parameters:
        itemset1 - the first itemset
        length - of the first itemset
        itemset2 - the second itemset
        Returns:
        true if yes, otherwise false
      • containsLEXPlus

        public static boolean containsLEXPlus​(int[] itemset,
                                              int item)
        This method checks if the item "item" is in the itemset. It asumes that items in the itemset are sorted in lexical order This version also checks that if the item "item" was added it would be the largest one according to the lexical order.
        Parameters:
        itemset - an itemset
        item - the item
        Returns:
        return true if the above conditions are met, otherwise false
      • containsLEX

        public static boolean containsLEX​(int[] itemset,
                                          int item)
        This method checks if the item "item" is in the itemset. It assumes that items in the itemset are sorted in lexical order
        Parameters:
        itemset - an itemset
        item - the item
        Returns:
        return true if the item
      • contains

        public static boolean contains​(int[] itemset,
                                       int item)
        Check if an a sorted list of integers contains an integer.
        Parameters:
        itemset - the sorted list of integers
        item - the integer
        Returns:
        true if the item appears in the list, false otherwise
      • appendIntegerToArray

        public static int[] appendIntegerToArray​(int[] array,
                                                 int integer)
        Append an integer at the end of an array of integers.
        Parameters:
        array - the array
        integer - the integer
        Returns:
        a new array
      • convertStringArrayToDoubleArray

        public static double[] convertStringArrayToDoubleArray​(java.lang.String[] tokens)
        Convert a string array to a double array
        Parameters:
        tokens - a string array
        Returns:
        a double array