libfsm icon indicating copy to clipboard operation
libfsm copied to clipboard

Caching for unary and binary libfsm operations

Open katef opened this issue 7 years ago • 0 comments

This ticket proposes a cache kept behind the scenes in libfsm, storing FSM as constructed by each fsm_*() unary or binary operation.

I'm picturing this as a limited-size associative array indexed by ID; when an operation is called, it'd combine the IDs for its operands to construct a new ID, and return fsm_clone() of that new ID, if one exists. The idea is that cloning is cheap, especially when we move to an adjacency list.

IDs would be stored per FSM. For constructing IDs, I imagine they'd be constructed of some bits representing the operation, and one or two other IDs as operands, and then that all gets hashed to produce a new ID.

I'm picturing this specifically for operations on one or two FSM only - and not for things like fsm_addedge_*() which modify an existing FSM. Maybe this is exactly only for <fsm/bool.h>.

I'm told in lisp, this is called "hash-consing".

This idea doesn't necessarily mean that all struct fsm objects would be immutable, although that's possible COW style, too. I think in particular things like fsm_addedge_*() would be unwieldy if they duplicate an FSM for every edge added.

katef avatar Jul 15 '18 17:07 katef