4.3 More about Dispatchers

Usually you need not care about the mechanism described in the previous section. You just call the dispatcher functions like Size. They will call the function in the operations record, which is hopefully implementing an algorithm that is well suited for their domain, by using the structure of this domain.

There are three reasons why you might want to avoid calling the dispatcher function and call the dispatched to function directly.

The first reason is efficiency. The dispatcher functions don't do very much. They only check the types of their arguments, check if the requested information is already present, and dispatch to the appropriate function in the operations record. But sometimes, for example in the innermost loop of your algorithm, even this little is too much. In those cases you can avoid the overhead introduced by the dispatcher function by calling the function in the operations record directly. For example, you would use G.operations.Size(G) instead of Size(G).

The second reason is flexibility. Sometimes you do not want to call the function in the operations record, but another function that performs the same task, using a different algorithm. In that case you will call this different function. For example, if G is a permutation group, and the orbit of p under G is very short, GroupOps.Orbit(G,p), which is the default function to compute an orbit, may be slightly more efficient than Orbit(G,p), which calls G.operations.Orbit(G,p), which is the same as PermGroupOps.Orbit(G,p).

The third has to do with the fact that the dispatcher functions check for knowledge components like D.size or D.elements and also store their result in such components. For example, suppose you know that the result of a computation takes up quite some space, as is the case with Elements(D), and that you will never need the value again. In this case you would not want the dispatcher function to enter the value in the domain record, and therefore would call D.operations.Elements(D) directly. On the other hand you may not want to use the value in the domain record, because you mistrust it. In this case you should call the function in the operations record directly, e.g., you would use G.operations.Size(G) instead of Size(G) (and then compare the result with G.size).

Previous Up Top Next
Index

GAP 3.4.4
April 1997