[m-dev.] for review: direct reuse
Ralph Becket
rbeck at microsoft.com
Thu Sep 21 20:53:04 AEDT 2000
>From Peter Ross on 21/09/2000 10:40:55
> By any chance did you come to a meeting where we discussed this?
:)
> case b)
>
> :- pred split(tree23(T)::in, tree23(T)::out) is det.
>
> split(X, Y) :-
> X => three(L, LK, M, RK, R),
> T <= two(L, LK, M), % reuse the three cell, but waste the two extra
> % words at the end of the cell.
> Y <= two(T, RK, R).
At first sight, this might seem fairly extravagant (40% wastage), until
you consider that applying reuse in an imperative language would probably
require something of the following order:
struct node {
enum {TWO, THREE, FOUR} tag;
union {
struct two_node two;
struct three_node three;
struct four_node four;
} body;
}
...
struct four_node {
Word key1; Word value1; ...; Word key3; Word value3;
struct node *tree0; struct node *tree1; ...; struct node *tree4;
}
which is certainly worse, except for the fact that, under the Mercury
scheme, having overwritten a larger cell with a smaller one, we no longer
have the information that there is some extra space available if we wanted
to go in the other direction.
Ralph
--
Ralph Becket | MSR Cambridge | rbeck at microsoft.com
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list