Class TrAct
- All Implemented Interfaces:
Serializable
,Cloneable
,Comparable<TrAct>
- Since:
- 2013.11.29
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTrAct()
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 TypeMethodDescriptionfinal 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
addItemByName
(String item) Add an item (given by its name) to the transaction.final int
addItemByObject
(Object item) Add an item (given by its object) to the transaction.final Object
clone()
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
Check whether a given other transaction is contained in this transaction.final int[]
Get the item array (length fits only after packing withpack()
; should be considered readonly).final int
getCount()
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
getItemObject
(int i) Get the object of an item.final int
getSize()
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
isContainedIn
(Pattern pat) Whether this transaction is contained in a given item pattern.final boolean
isContainedIn
(TrAct tract) Whether this transaction is contained in a given other transaction.final void
pack()
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 a transaction.static TrAct
Parse a transaction.static TrAct
Parse a transaction.static TrAct
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()
Sort the items in a transaction (by item identifier).final String
toString()
Create a string description.final String
toString
(boolean wgt) Create a string description.final String
Create a string description.Create a string description.final void
Write a transaction.final void
Write a transaction.final void
Write a transaction.final void
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.
-
Field Details
-
ibase
protected util.IdMap ibasethe underlying item base -
items
protected int[] itemsthe items of the transaction -
size
protected int sizethe current number of items -
wgt
protected int wgtthe 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 basewgt
- 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 baseitems
- the array of item identifierswgt
- 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 baseitems
- the array of item identifierscnt
- the number of items (may be smaller thanitems.length
)wgt
- the weight/multiplicity of the transaction (number of occurrences)- Since:
- 2017.06.19 (Christian Borgelt)
-
-
Method Details
-
clone
Clone this transaction (the item base is maintained, the item array is copied). -
clone
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
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
Clone this transaction (the item base is maintained).- Parameters:
iclone
- whether to clone the item arrayibase
- the item base to use for the clone- Returns:
- a clone of this transaction
- Since:
- 2017.06.19 (Christian Borgelt)
-
clone
Clone this transaction (the item base is maintained).- Parameters:
ibase
- the item base to use for the cloneiclone
- 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
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
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
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
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
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
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 withpack()
; 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
Compare this transaction to another (given as argument).- Specified by:
compareTo
in interfaceComparable<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 arrayitems
also need to be sorted (by identifier) for this function to work.- Parameters:
items
- the array of items to checkcnt
- the number of items in the given array to consider; if negative, the length of the item arrayitems
is used- Returns:
true
is this transaction contains the given items initems
andfalse
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 arrayitems
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 initems
andfalse
otherwise- Since:
- 2017.06.20 (Christian Borgelt)
-
contains
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 patternpat
andfalse
otherwise- Since:
- 2017.06.20 (Christian Borgelt)
-
contains
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 transactiontract
andfalse
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 arrayitems
also need to be sorted (by identifier).- Parameters:
items
- the array of items to checkcnt
- 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 itemsitems
andfalse
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 arrayitems
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 itemsitems
andfalse
otherwise- Since:
- 2017.06.20 (Christian Borgelt)
-
isContainedIn
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 patternpat
andfalse
otherwise- Since:
- 2017.06.20 (Christian Borgelt)
-
isContainedIn
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 transactiontract
andfalse
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 checkcnt
- the number of items in the given array to consider; if negative, the length of the item arrayitems
is 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 findoffset
- 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 tomap
- the old identifier to new identifier map; ifnull
, the map is created by a call toIdMap.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
Write a transaction.- Parameters:
writer
- the writer to write to- Throws:
IOException
- if a write error occurs- Since:
- 2017.06.29 (Christian Borgelt)
-
write
Write a transaction.- Parameters:
writer
- the writer to write toisep
- the item separator- Throws:
IOException
- if a write error occurs- Since:
- 2017.06.29 (Christian Borgelt)
-
write
Write a transaction.- Parameters:
writer
- the writer to write towgt
- whether to write a transaction weight- Throws:
IOException
- if a write error occurs- Since:
- 2017.06.29 (Christian Borgelt)
-
write
Write a transaction.- Parameters:
writer
- the writer to write toisep
- the item separatorwgt
- whether to write a transaction weight- Throws:
IOException
- if a write error occurs- Since:
- 2017.06.27 (Christian Borgelt)
-
write
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
Write a transaction with a table writer.- Parameters:
writer
- the table writer to write towgt
- 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 basereader
- the reader to read fromwgt
- 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
Parse a transaction.- Parameters:
ibase
- the underlying item basereader
- the reader to read from- Returns:
- the parsed transaction
- Throws:
IOException
- if a read error occurs- Since:
- 2013.11.29 (Christian Borgelt)
-
parse
Parse a transaction.- Parameters:
ibase
- the underlying item basereader
- the reader to read fromwgt
- 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
Parse a transaction.- Parameters:
ibase
- the underlying item basereader
- the reader to read from- Returns:
- the parsed transaction
- Throws:
IOException
- if a read error occurs- Since:
- 2013.11.28 (Christian Borgelt)
-
parse
Parse a transaction.- Parameters:
ibase
- the underlying item basedesc
- the string description to parsewgt
- 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
Parse a transaction.- Parameters:
ibase
- the underlying item basedesc
- the string description to parse- Returns:
- the parsed transaction
- Throws:
IOException
- if a read error occurs- Since:
- 2013.11.28 (Christian Borgelt)
-
parse
Parse a transaction.- Parameters:
ibase
- the underlying item baseinp
- the input stream to read fromwgt
- 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
Parse a transaction.- Parameters:
ibase
- the underlying item baseinp
- the input stream to read from- Returns:
- the parsed transaction
- Throws:
IOException
- if a read error occurs- Since:
- 2013.11.28 (Christian Borgelt)
-
toString
Create a string description.- Parameters:
isep
- the item separatorwgt
- whether to write a transaction weight- Returns:
- the created string description
- Since:
- 2013.11.28 (Christian Borgelt)
-
toString
Create a string description.- Parameters:
isep
- the item separator- Returns:
- the created string description
- Since:
- 2013.11.28 (Christian Borgelt)
-
toString
Create a string description.- Parameters:
wgt
- whether to write a transaction weight- Returns:
- the created string description
- Since:
- 2017.06.29 (Christian Borgelt)
-
toString
Create a string description.
-