Skip to content

Commit 5291fb1

Browse files
documented event broker
1 parent 92156cf commit 5291fb1

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

sklearn/tree/_events.pxd

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,37 @@
77
from libcpp.vector cimport vector
88
from ..utils._typedefs cimport float32_t, float64_t, intp_t, int32_t, uint32_t
99

10+
11+
# a simple, general purpose event broker.
12+
#
13+
# it utilizes a somewhat clunky interface built around an event handler closure
14+
# struct, as we are trying to balance generality with execution speed, and in
15+
# practice nothing's faster than simply applying a function pointer.
16+
#
17+
# the idea is we would like something like a closure for event handlers, so that
18+
# we may bind instances to instance-specific parameter values, like say you have
19+
# a "threshold" parameter and you would like threshold-dependent handler behavior,
20+
# but you want this threshold configurable at runtime. so we keep this threshold
21+
# parameter in an environment bound to a "closure" instance, which is just a struct
22+
# with a pointer to the environment instance and handler function. now vectors of
23+
# these closures are compact, fast to iterate through, and low overhead to execute.
24+
#
25+
# the idea with EventType is that you have an event broker handling a class of
26+
# conceptually related events, like suppose "server" events, and EventType would
27+
# typically be values from an enum like say:
28+
#
29+
# cdef enum ServerEvent:
30+
# SERVER_UP = 1
31+
# SERVER_DOWN = 2
32+
# SERVER_ON_FIRE = 3
33+
#
34+
# an assumption of the current implementation is that these enum values are small
35+
# integers, and we use them to allocate and index into a listener vector.
36+
#
37+
# EventData is simply a pointer to whatever event payload information is relevant
38+
# to your handler, and it is expected that event_type maps to an associated handler
39+
# which knows what specific "concrete" type to cast its event_data to.
40+
1041
ctypedef int EventType
1142
ctypedef void* EventHandlerEnv
1243
ctypedef void* EventData

0 commit comments

Comments
 (0)