Package fim

Class TrAct

java.lang.Object
fim.TrAct
All Implemented Interfaces:
Serializable, Cloneable, Comparable<TrAct>

public class TrAct extends Object implements Comparable<TrAct>, Cloneable, Serializable
Class for transactions.
Since:
2013.11.29
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected util.IdMap
    the underlying item base
    protected int[]
    the items of the transaction
    protected int
    the current number of items
    protected int
    the weight/multiplicity of the transaction (number of occurrences)
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create an empty transaction.
    TrAct(util.IdMap ibase)
    Create an empty transaction.
    TrAct(util.IdMap ibase, int wgt)
    Create an empty transaction.
    TrAct(util.IdMap ibase, int[] items, int wgt)
    Create a transaction from an item array (the given item array is stored, not copied).
    TrAct(util.IdMap ibase, int[] items, int cnt, int wgt)
    Create a transaction from an item array (the given item array is copied).
  • Method Summary

    Modifier and Type
    Method
    Description
    final int
    addItem(int item)
    Add an item (given by its identifier) to the transaction.
    final int
    Add an item (given by its object) to the transaction.
    final int
    Add an item (given by its name) to the transaction.
    final int
    addItemById(int item)
    Add an item to the transaction.
    final int
    Add an item (given by its name) to the transaction.
    final int
    Add an item (given by its object) to the transaction.
    final Object
    Clone this transaction (the item base is maintained, the item array is copied).
    final Object
    clone(boolean iclone)
    Clone this transaction (the item base is maintained).
    final Object
    clone(boolean iclone, util.IdMap ibase)
    Clone this transaction (the item base is maintained).
    final Object
    clone(util.IdMap ibase)
    Clone this transaction (the item array is copied).
    clone(util.IdMap ibase, boolean iclone)
    Clone this transaction (the item base is maintained).
    int
    Compare this transaction to another (given as argument).
    final boolean
    contains(int[] items)
    Check whether a given item pattern is contained in this transaction.
    final boolean
    contains(int[] items, int cnt)
    Check whether a given item pattern is contained in this transaction.
    final boolean
    Check whether a given item pattern is contained in this transaction.
    final boolean
    contains(TrAct tract)
    Check whether a given other transaction is contained in this transaction.
    final int[]
    Get the item array (length fits only after packing with pack(); should be considered readonly).
    final int
    Get the size of the transaction (number of items).
    final int
    getItem(int i)
    Get an item (i.e., its identifier).
    final int
    getItemId(int i)
    Get an item (i.e., its identifier).
    final String
    getItemName(int i)
    Get the name of an item.
    final Object
    Get the object of an item.
    final int
    Get the size of the transaction (number of items).
    final int
    getSuffix(int[] items)
    Get the offset to the start of the suffix after the first occurrence of an item pattern.
    final int
    getSuffix(int[] items, int cnt)
    Get the offset to the start of the suffix after the first occurrence of an item pattern.
    final int
    Get the weight/multiplicity of the transaction (number of occurrences).
    final int
    indexOf(int item)
    Find the index of the (first) occurrence of an item.
    final int
    indexOf(int item, int offset)
    Find the index of the (first) occurrence of an item.
    final boolean
    isContainedIn(int[] items)
    Whether this transaction is contained in a given item pattern.
    final boolean
    isContainedIn(int[] items, int cnt)
    Whether this transaction is contained in a given item pattern.
    final boolean
    Whether this transaction is contained in a given item pattern.
    final boolean
    Whether this transaction is contained in a given other transaction.
    final void
    Pack a transaction, i.e., optimize memory usage.
    static TrAct
    parse(util.IdMap ibase, InputStream inp)
    Parse a transaction.
    static TrAct
    parse(util.IdMap ibase, InputStream inp, boolean wgt)
    Parse a transaction.
    static TrAct
    parse(util.IdMap ibase, Reader reader)
    Parse a transaction.
    static TrAct
    parse(util.IdMap ibase, Reader reader, boolean wgt)
    Parse a transaction.
    static TrAct
    parse(util.IdMap ibase, String desc)
    Parse a transaction.
    static TrAct
    parse(util.IdMap ibase, String desc, boolean wgt)
    Parse a transaction.
    static TrAct
    parse(util.IdMap ibase, util.TableReader reader)
    Parse a transaction.
    static TrAct
    parse(util.IdMap ibase, util.TableReader reader, boolean wgt)
    Parse a transaction.
    final void
    recodeTo(util.IdMap ibase)
    Recode a transaction to another item base, replacing the item base.
    final void
    recodeTo(util.IdMap ibase, int[] map)
    Recode a transaction to another item base, replacing the item base.
    final int
    reduce(int[] map)
    Reduce the items of a transaction (remove infrequent items).
    final int
    setWeight(int wgt)
    Set the weight/multiplicity of the transaction (number of occurrences).
    final void
    Sort the items in a transaction (by item identifier).
    final String
    Create a string description.
    final String
    toString(boolean wgt)
    Create a string description.
    final String
    Create a string description.
    toString(String isep, boolean wgt)
    Create a string description.
    final void
    write(Writer writer)
    Write a transaction.
    final void
    write(Writer writer, boolean wgt)
    Write a transaction.
    final void
    write(Writer writer, String isep)
    Write a transaction.
    final void
    write(Writer writer, String isep, boolean wgt)
    Write a transaction.
    final void
    write(util.TableWriter writer)
    Write a transaction with a table writer.
    final void
    write(util.TableWriter writer, boolean wgt)
    Write a transaction with a table writer.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • ibase

      protected util.IdMap ibase
      the underlying item base
    • items

      protected int[] items
      the items of the transaction
    • size

      protected int size
      the current number of items
    • wgt

      protected int wgt
      the weight/multiplicity of the transaction (number of occurrences)
  • Constructor Details

    • TrAct

      public TrAct()
      Create an empty transaction.
      Since:
      2013.11.29 (Christian Borgelt)
    • TrAct

      public TrAct(util.IdMap ibase)
      Create an empty transaction.
      Parameters:
      ibase - the underlying item base
      Since:
      2013.11.29 (Christian Borgelt)
    • TrAct

      public TrAct(util.IdMap ibase, int wgt)
      Create an empty transaction.
      Parameters:
      ibase - the underlying item base
      wgt - the weight/multiplicity of the transaction (number of occurrences)
      Since:
      2014.10.02 (Christian Borgelt)
    • TrAct

      public TrAct(util.IdMap ibase, int[] items, int wgt)
      Create a transaction from an item array (the given item array is stored, not copied).
      Parameters:
      ibase - the underlying item base
      items - the array of item identifiers
      wgt - the weight/multiplicity of the transaction (number of occurrences)
      Since:
      2017.06.19 (Christian Borgelt)
    • TrAct

      public TrAct(util.IdMap ibase, int[] items, int cnt, int wgt)
      Create a transaction from an item array (the given item array is copied).
      Parameters:
      ibase - the underlying item base
      items - the array of item identifiers
      cnt - the number of items (may be smaller than items.length)
      wgt - the weight/multiplicity of the transaction (number of occurrences)
      Since:
      2017.06.19 (Christian Borgelt)
  • Method Details

    • clone

      public final Object clone()
      Clone this transaction (the item base is maintained, the item array is copied).
      Overrides:
      clone in class Object
      Returns:
      a clone of this transaction
      Since:
      2017.06.19 (Christian Borgelt)
    • clone

      public final Object clone(util.IdMap ibase)
      Clone this transaction (the item array is copied).
      Parameters:
      ibase - the item base to use for the clone
      Returns:
      a clone of this transaction
      Since:
      2017.06.19 (Christian Borgelt)
    • clone

      public final Object clone(boolean iclone)
      Clone this transaction (the item base is maintained).
      Parameters:
      iclone - whether to clone the item array
      Returns:
      a clone of this transaction
      Since:
      2017.06.19 (Christian Borgelt)
    • clone

      public final Object clone(boolean iclone, util.IdMap ibase)
      Clone this transaction (the item base is maintained).
      Parameters:
      iclone - whether to clone the item array
      ibase - the item base to use for the clone
      Returns:
      a clone of this transaction
      Since:
      2017.06.19 (Christian Borgelt)
    • clone

      public Object clone(util.IdMap ibase, boolean iclone)
      Clone this transaction (the item base is maintained).
      Parameters:
      ibase - the item base to use for the clone
      iclone - whether to clone the item array
      Returns:
      a clone of this transaction
      Since:
      2017.06.19 (Christian Borgelt)
    • addItemById

      public final int addItemById(int item)
      Add an item to the transaction.
      Parameters:
      item - the item identifier
      Returns:
      the index of the new item
      Since:
      2013.11.29 (Christian Borgelt)
    • addItemByName

      public final int addItemByName(String item)
      Add an item (given by its name) to the transaction.
      Parameters:
      item - the name of the item to add
      Returns:
      the index of the new item
      Since:
      2013.11.29 (Christian Borgelt)
    • addItemByObject

      public final int addItemByObject(Object item)
      Add an item (given by its object) to the transaction.
      Parameters:
      item - the object of the item to add
      Returns:
      the index of the new item
      Since:
      2017.06.19 (Christian Borgelt)
    • addItem

      public final int addItem(int item)
      Add an item (given by its identifier) to the transaction.
      Parameters:
      item - the identifier of the item to add
      Returns:
      the index of the new item
      Since:
      2017.06.20 (Christian Borgelt)
    • addItem

      public final int addItem(String item)
      Add an item (given by its name) to the transaction.
      Parameters:
      item - the name of the item to add
      Returns:
      the index of the new item
      Since:
      2017.06.20 (Christian Borgelt)
    • addItem

      public final int addItem(Object item)
      Add an item (given by its object) to the transaction.
      Parameters:
      item - the object of the item to add
      Returns:
      the index of the new item
      Since:
      2017.06.20 (Christian Borgelt)
    • getItem

      public final int getItem(int i)
      Get an item (i.e., its identifier).
      Parameters:
      i - the index of the item
      Returns:
      the identifier of the item
      Since:
      2013.11.29 (Christian Borgelt)
    • getItemId

      public final int getItemId(int i)
      Get an item (i.e., its identifier).
      Parameters:
      i - the index of the item
      Returns:
      the identifier of the item
      Since:
      2017.06.20 (Christian Borgelt)
    • getItemName

      public final String getItemName(int i)
      Get the name of an item.
      Parameters:
      i - the index of the item
      Returns:
      the name of the item
      Since:
      2013.11.29 (Christian Borgelt)
    • getItemObject

      public final Object getItemObject(int i)
      Get the object of an item.
      Parameters:
      i - the index of the item
      Returns:
      the name of the item
      Since:
      2013.11.29 (Christian Borgelt)
    • getAllItems

      public final int[] getAllItems()
      Get the item array (length fits only after packing with pack(); should be considered readonly).
      Returns:
      the item array (which is possibly oversized)
      Since:
      2014.10.03 (Christian Borgelt)
    • getSize

      public final int getSize()
      Get the size of the transaction (number of items).
      Returns:
      the size of the transaction
      Since:
      2013.11.29 (Christian Borgelt)
    • getCount

      public final int getCount()
      Get the size of the transaction (number of items).
      Returns:
      the size of the transaction
      Since:
      2017.06.19 (Christian Borgelt)
    • getWeight

      public final int getWeight()
      Get the weight/multiplicity of the transaction (number of occurrences).
      Returns:
      the weight/multiplicity of the transaction
      Since:
      2014.10.02 (Christian Borgelt)
    • setWeight

      public final int setWeight(int wgt)
      Set the weight/multiplicity of the transaction (number of occurrences).
      Parameters:
      wgt - the weight/multiplicity of the transaction
      Returns:
      the passed weight (for convenience)
      Since:
      2014.10.02 (Christian Borgelt)
    • compareTo

      public int compareTo(TrAct tract)
      Compare this transaction to another (given as argument).
      Specified by:
      compareTo in interface Comparable<TrAct>
      Parameters:
      tract - the other transaction to compare to
      Returns:
      -1, 0, or +1 as this transaction is less than, equal to, or greater than the given transaction (argument)
      Since:
      2017.06.20 (Christian Borgelt)
    • reduce

      public final int reduce(int[] map)
      Reduce the items of a transaction (remove infrequent items).
      Parameters:
      map - the old to new item identifier map: a negative value means that the item is to be removed, a non-negative value states the new item identifier
      Returns:
      the new number of items
      Since:
      2017.06.20 (Christian Borgelt)
    • sort

      public final void sort()
      Sort the items in a transaction (by item identifier).
      Since:
      2017.06.20 (Christian Borgelt)
    • contains

      public final boolean contains(int[] items, int cnt)
      Check whether a given item pattern is contained in this transaction.

      For item permutations and sequences the function works directly, but for item sets the transaction needs to be sorted with sort() first and the items in the passed array items also need to be sorted (by identifier) for this function to work.

      Parameters:
      items - the array of items to check
      cnt - the number of items in the given array to consider; if negative, the length of the item array itemsis used
      Returns:
      true is this transaction contains the given items in items and false otherwise
      Since:
      2017.06.20 (Christian Borgelt)
    • contains

      public final boolean contains(int[] items)
      Check whether a given item pattern is contained in this transaction.

      For item permutations and sequences the function works directly, but for item sets the transaction needs to be sorted with sort() first and the items in the passed array items also need to be sorted (by identifier) for this function to work.

      Parameters:
      items - the array of items to check
      Returns:
      true is this transaction contains the given items in items and false otherwise
      Since:
      2017.06.20 (Christian Borgelt)
    • contains

      public final boolean contains(Pattern pat)
      Check whether a given item pattern is contained in this transaction.

      For item permutations and sequences the function works directly, but for item sets both the transaction and the item set need to be sorted with sort() for this function to work.

      Parameters:
      pat - the item pattern to check whether it is contained
      Returns:
      true if this transaction contains the given item pattern pat and false otherwise
      Since:
      2017.06.20 (Christian Borgelt)
    • contains

      public final boolean contains(TrAct tract)
      Check whether a given other transaction is contained in this transaction.

      For item permutations and sequences the function works directly, but for item sets both transactions need to be sorted with sort() for this function to work.

      Parameters:
      tract - the other transaction to check whether it is contained
      Returns:
      true is this transaction contains the given transaction tract and false otherwise
      Since:
      2017.06.20 (Christian Borgelt)
    • isContainedIn

      public final boolean isContainedIn(int[] items, int cnt)
      Whether this transaction is contained in a given item pattern.

      For item permutations and sequences the function works directly, but for item sets the transaction needs to be sorted with sort() and the items in the passed array items also need to be sorted (by identifier).

      Parameters:
      items - the array of items to check
      cnt - the number of items in the given array to consider; if negative, the length of the item array is used
      Returns:
      true if this transaction is contained in the given items items and false otherwise
      Since:
      2017.06.20 (Christian Borgelt)
    • isContainedIn

      public final boolean isContainedIn(int[] items)
      Whether this transaction is contained in a given item pattern.

      For item permutations and sequences the function works directly, but for item sets the transaction needs to be sorted with sort() and the items in the passed array items also need to be sorted (by identifier).

      Parameters:
      items - the array of items to check
      Returns:
      true if this transaction is contained in the given items items and false otherwise
      Since:
      2017.06.20 (Christian Borgelt)
    • isContainedIn

      public final boolean isContainedIn(Pattern pat)
      Whether this transaction is contained in a given item pattern.

      For item permutations and sequences the function works directly, but for item sets, both the transaction and the item set need to be sorted with sort() for this function to work.

      Parameters:
      pat - the item pattern to check
      Returns:
      true if this transaction is contained in the given item pattern pat and false otherwise
      Since:
      2017.06.20 (Christian Borgelt)
    • isContainedIn

      public final boolean isContainedIn(TrAct tract)
      Whether this transaction is contained in a given other transaction.

      For item permutations and sequences the function works directly, but for item sets, both transactions must have been sorted with sort() for this function to work.

      Parameters:
      tract - the other transaction to check
      Returns:
      true if this transaction is contained in the given other transaction tract and false otherwise
      Since:
      2017.06.20 (Christian Borgelt)
    • getSuffix

      public final int getSuffix(int[] items, int cnt)
      Get the offset to the start of the suffix after the first occurrence of an item pattern.
      Parameters:
      items - the array of items to check
      cnt - the number of items in the given array to consider; if negative, the length of the item array itemsis used
      Returns:
      the offset to the start of the suffix after the first occurrence of the given item pattern, or -1 if the item pattern does not occur
      Since:
      2017.06.20 (Christian Borgelt)
    • getSuffix

      public final int getSuffix(int[] items)
      Get the offset to the start of the suffix after the first occurrence of an item pattern.
      Parameters:
      items - the array of items to check
      Returns:
      the offset to the start of the suffix after the first occurrence of the given item pattern, or -1 if the item pattern does not occur
      Since:
      2017.06.20 (Christian Borgelt)
    • indexOf

      public final int indexOf(int item, int offset)
      Find the index of the (first) occurrence of an item.
      Parameters:
      item - the identifier of the item to find
      offset - the offset at which to start the search
      Returns:
      the index of the (first) occurrence of an item, or -1 if the item does not occur
      Since:
      2017.06.20 (Christian Borgelt)
    • indexOf

      public final int indexOf(int item)
      Find the index of the (first) occurrence of an item.
      Parameters:
      item - the identifier of the item to find
      Returns:
      the index of the (first) occurrence of an item, or -1 if the item does not occur
      Since:
      2017.06.20 (Christian Borgelt)
    • recodeTo

      public final void recodeTo(util.IdMap ibase, int[] map)
      Recode a transaction to another item base, replacing the item base.
      Parameters:
      ibase - the item base to recode the transaction to
      map - the old identifier to new identifier map; if null, the map is created by a call to IdMap.getMapTo()
      Since:
      2017.06.20 (Christian Borgelt)
    • recodeTo

      public final void recodeTo(util.IdMap ibase)
      Recode a transaction to another item base, replacing the item base.
      Parameters:
      ibase - the item base to recode the transaction to
      Since:
      2017.06.20 (Christian Borgelt)
    • pack

      public final void pack()
      Pack a transaction, i.e., optimize memory usage.
      Since:
      2013.11.29 (Christian Borgelt)
    • write

      public final void write(Writer writer) throws IOException
      Write a transaction.
      Parameters:
      writer - the writer to write to
      Throws:
      IOException - if a write error occurs
      Since:
      2017.06.29 (Christian Borgelt)
    • write

      public final void write(Writer writer, String isep) throws IOException
      Write a transaction.
      Parameters:
      writer - the writer to write to
      isep - the item separator
      Throws:
      IOException - if a write error occurs
      Since:
      2017.06.29 (Christian Borgelt)
    • write

      public final void write(Writer writer, boolean wgt) throws IOException
      Write a transaction.
      Parameters:
      writer - the writer to write to
      wgt - whether to write a transaction weight
      Throws:
      IOException - if a write error occurs
      Since:
      2017.06.29 (Christian Borgelt)
    • write

      public final void write(Writer writer, String isep, boolean wgt) throws IOException
      Write a transaction.
      Parameters:
      writer - the writer to write to
      isep - the item separator
      wgt - whether to write a transaction weight
      Throws:
      IOException - if a write error occurs
      Since:
      2017.06.27 (Christian Borgelt)
    • write

      public final void write(util.TableWriter writer) throws IOException
      Write a transaction with a table writer.
      Parameters:
      writer - the table writer to write to
      Throws:
      IOException - if a write error occurs
      Since:
      2007.06.06 (Christian Borgelt)
    • write

      public final void write(util.TableWriter writer, boolean wgt) throws IOException
      Write a transaction with a table writer.
      Parameters:
      writer - the table writer to write to
      wgt - whether to write the transaction weight
      Throws:
      IOException - if a write error occurs
      Since:
      2014.10.02 (Christian Borgelt)
    • parse

      public static TrAct parse(util.IdMap ibase, util.TableReader reader, boolean wgt) throws IOException
      Parse a transaction.
      Parameters:
      ibase - the underlying item base
      reader - the reader to read from
      wgt - whether to read a transaction weight/multiplicity
      Returns:
      the parsed transaction
      Throws:
      IOException - if a read error occurs
      Since:
      2013.11.29 (Christian Borgelt)
    • parse

      public static TrAct parse(util.IdMap ibase, util.TableReader reader) throws IOException
      Parse a transaction.
      Parameters:
      ibase - the underlying item base
      reader - the reader to read from
      Returns:
      the parsed transaction
      Throws:
      IOException - if a read error occurs
      Since:
      2013.11.29 (Christian Borgelt)
    • parse

      public static TrAct parse(util.IdMap ibase, Reader reader, boolean wgt) throws IOException
      Parse a transaction.
      Parameters:
      ibase - the underlying item base
      reader - the reader to read from
      wgt - whether to read a transaction weight/multiplicity
      Returns:
      the parsed transaction
      Throws:
      IOException - if a read error occurs
      Since:
      2014.10.02 (Christian Borgelt)
    • parse

      public static TrAct parse(util.IdMap ibase, Reader reader) throws IOException
      Parse a transaction.
      Parameters:
      ibase - the underlying item base
      reader - the reader to read from
      Returns:
      the parsed transaction
      Throws:
      IOException - if a read error occurs
      Since:
      2013.11.28 (Christian Borgelt)
    • parse

      public static TrAct parse(util.IdMap ibase, String desc, boolean wgt) throws IOException
      Parse a transaction.
      Parameters:
      ibase - the underlying item base
      desc - the string description to parse
      wgt - whether to read a transaction weight/multiplicity
      Returns:
      the parsed transaction
      Throws:
      IOException - if a read error occurs
      Since:
      2014.10.02 (Christian Borgelt)
    • parse

      public static TrAct parse(util.IdMap ibase, String desc) throws IOException
      Parse a transaction.
      Parameters:
      ibase - the underlying item base
      desc - the string description to parse
      Returns:
      the parsed transaction
      Throws:
      IOException - if a read error occurs
      Since:
      2013.11.28 (Christian Borgelt)
    • parse

      public static TrAct parse(util.IdMap ibase, InputStream inp, boolean wgt) throws IOException
      Parse a transaction.
      Parameters:
      ibase - the underlying item base
      inp - the input stream to read from
      wgt - whether to read a transaction weight/multiplicity
      Returns:
      the parsed transaction
      Throws:
      IOException - if a read error occurs
      Since:
      2014.10.02 (Christian Borgelt)
    • parse

      public static TrAct parse(util.IdMap ibase, InputStream inp) throws IOException
      Parse a transaction.
      Parameters:
      ibase - the underlying item base
      inp - the input stream to read from
      Returns:
      the parsed transaction
      Throws:
      IOException - if a read error occurs
      Since:
      2013.11.28 (Christian Borgelt)
    • toString

      public String toString(String isep, boolean wgt)
      Create a string description.
      Parameters:
      isep - the item separator
      wgt - whether to write a transaction weight
      Returns:
      the created string description
      Since:
      2013.11.28 (Christian Borgelt)
    • toString

      public final String toString(String isep)
      Create a string description.
      Parameters:
      isep - the item separator
      Returns:
      the created string description
      Since:
      2013.11.28 (Christian Borgelt)
    • toString

      public final String toString(boolean wgt)
      Create a string description.
      Parameters:
      wgt - whether to write a transaction weight
      Returns:
      the created string description
      Since:
      2017.06.29 (Christian Borgelt)
    • toString

      public final String toString()
      Create a string description.
      Overrides:
      toString in class Object
      Returns:
      the created string description
      Since:
      2013.11.28 (Christian Borgelt)