The Phreak algorithm is a Rule matching algorithm, based upon the Rete algorithm, as described in the paper "Production Matching for Large Learning Systems" by Robert B. Doorenbos, January 31, 1995, CMU-CS-95-113
The algorithm is used to match facts against a number of rules to see if any combination triggers the rule. A rule is called a production, and when a combination of facts matches the rule, it is called an activation.
The phreak algorithm is implemented by the Drools project. We are not trying to create a java to rust port, but instead we are building an algorithm from scratch with the ideas from the Drools documentation.
We aim to use only safe rust code.
We are trying to obtain a good performance by focusing on the following concepts:
The fastest code is code you don't execute.
Cache friendly evaluation
By grouping data evaluation, we try to optimize cache usage for the CPU.
Minimize data allocations
Allocations are slow, so they should be avoided. We use the rust ownership model to safely pass around data instead of passing on copies.
Scheduled actions with helper functions
The nodes module contains the Alpha and Beta network nodes, and holds the bulk of the process logic.
The conditions module holds the structures for composing a low level rule definition
The core module contains the main api of the phreak algorithm, as well as the central data storage.
The jointest module contains the logic for performing test evaluation. Whenever two facts need to be compared, we say that they are joined if the tests for this combination of facts succeeds.
The memory module contains structures for storing information about the execution of the rules. We have Memory structures that represent the information about a field, and Work Memory Entities that store information about a matching fact.
The nodes module contains the code for Alpha and Betanodes
The segments module contains a structure for independent network segments. Segments are independent if none of the nodes in the segment are shared with an other segment.
Some generic traits for thealpha and betanetwork are defined here.