[m-dev.] for review: use bitsets in quantification

Zoltan Somogyi zs at cs.mu.OZ.AU
Wed Nov 8 15:23:39 AEDT 2000


On 08-Nov-2000, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> It would probably be more efficient to check if the bit is already set,
> and if so return Set = Set0, avoiding two memory allocations.
> i.e. instead of
> 
> 		Bits = set_bit(Data0 ^ bits, BitToSet),
> 		Set = [make_bitset_elem(Offset0, Bits) | Rest]
> 
> you could have
> 
> 		( get_bit(Data0^bits, BitToSet) \= 0 ->
> 			Set = Set0
> 		;
> 			Bits = set_bit(Data0 ^ bits, BitToSet),
> 			Set = [make_bitset_elem(Offset0, Bits) | Rest]
> 		)

This will actually be a pessimization if the program never calls this code
with data that cases the condition to be true. A significant number of
algorithms never insert a given element into a set twice.

One (ugly) solution is to have two versions of this predicate, one with the
if-then-else and one without.

Zoltan.
--------------------------------------------------------------------------
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