Trigger with state example

I’d like to see an examples of how a trigger can be written which does not use () as the state type. So far I can’t find any in the documentation. I have a trigger which needs to see whenever a new contract for a particular template is created. My thinking was to store a set of contract IDs in the state: my updateState function can insert the new contract IDs whenever a CreatedEvent occurs. Then I realized it would simpler to use () for my state and do a linear scan of all active contracts inside my rule function - using query. However this seems quite wasteful having to do a linear time operation on every call of rule.