Hi Cyril,
an interesting problem, that you have there. :-)
The functions itertools.groupby() may help you. Here is a rough scetch:
----
import functools
import itertools
def filterfunc(store, min_count, item):
# keyfunc = lambda i: i.type # for complex types
keyfunc = lambda i: i # for simple types, e.g. strings
sorted_items = sorted(store.items, key=keyfunc)
key_found = None
for k, g in itertools.groupby(sorted_items, keyfunc):
if len(list(g)) >= min_count:
key_found = k
break
if key_found is None:
return False
return keyfunc(item) == key_found
store = FilterStore(...)
filterfunc = functools.partial(filterfunc, store, 10)
def proc(...)
result = yield store.get(filterfunc)
----
Note that this approach has O(n^2) because the the filterfunc is applied to
every object in the store (until one satisfies the filterfunc) and the
filterfunc itself iterates over all objects in the store.
If it gets to slow you may need to implement a custom FilterStore or FilterStoreGet event where you only run the groupby-stuff once before you
iterate all items in the store and apply the filter function.
Cheers,
Stefan
> --
> You received this message because you are subscribed to the Google Groups "python-simpy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
python-simpy...@googlegroups.com.
> To post to this group, send email to
python...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/python-simpy/b74a0509-72b4-4cc3-93ad-52a96c30ca3d%40googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.