mineLogic<T> function
The core recursive mining logic of the FP-Growth algorithm.
It iterates through the frequent items in a conditional tree (sorted by frequency), and for each item, it initiates a recursive mining step via mineForItem.
Implementation
Map<List<int>, int> mineLogic<T>(
FPTree tree,
List<int> prefix,
Map<int, int> frequency,
int absoluteMinSupport,
ItemMapper<T> mapper,
Logger logger,
) {
final frequentItemsets = <List<int>, int>{};
// Sort items by frequency (ascending) to process from least to most frequent
final entries = frequency.entries.toList()
..sort((a, b) {
final compare = a.value.compareTo(b.value);
if (compare == 0) {
return a.key.compareTo(b.key);
}
return compare;
});
final sortedItems = entries.map((e) => e.key).toList();
logger.debug(
'Mining conditional tree for prefix: ${prefix.map(mapper.getItem).join(', ')}',
);
for (final item in sortedItems) {
final itemResult = mineForItem(
tree,
item,
prefix,
frequency,
absoluteMinSupport,
mapper,
logger,
);
frequentItemsets.addAll(itemResult);
}
return frequentItemsets;
}