On 12/17/24 23:59, Waldek Hebisch wrote:
'positiveRemainder' (that is about 30% of 'localSearch' is due to 'positiveRemainder'). 'positiveRemainder' is more expensive than necessary, because it can handle Integer. However, AFAICS the
numbers involved are nonnegative SingleInteger-s and 'rem' from
SingleInteger should work fine.

Looking at the code I wonder a bit why I used both Integer and
SingleInteger. The reason must have been that PrimitiveArray(S) uses
#: % -> NonNegativeInteger and elt: (%, Integer) -> S, but we have
hash: % -> SingleInteger. So we must anyway have a conversion between Integer and SingleInteger, although we could for efficiency reasons let XHashTable use an adhoc implementation of PrimitiveArray (which is not seen outside of XHashTable) that uses SingleInteger for indexing. OK, but that was not your question.

The positiveness is important to get a proper index into the array.
And no, the numbers involved are not necessarily only non-negative.

1) The value function from HashState claims to return a SingleInteger
   (see http://fricas.github.io/api/HashState.html) and not a
   "non-negative SingleInteger".

2) In XHashTable, one can create a new table via the function
   table: (Key -> SingleInteger) -> %.

While (1) can easily be resolved by adding some text to the specification of "value" saying that the returned integer will be non-negative (because according to our current implementation it is, in fact, the case), I am not so sure about (2). Requiring the user to provide only hash functions that return non-negative SingleInteger, is possible, but I fear that this might be overlooked and then leading to
indexing errors while using XHashTable.

I would rather keep a safety meassure inside XHashTable. And probably that was the reason why I chose positiveRemainder over rem.

Thinking about that actual reason for XHashTable, it makes, of course, sense to care about efficiency. However, I started this domain, because there was nothing that would allow me my own hashing function. So

table: (Key -> SingleInteger) -> %

is an important function.

Discussion is open of what compromise between speed and safety is to be taken here.

Ralf

--
You received this message because you are subscribed to the Google Groups "FriCAS - 
computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/fricas-devel/a36eeaff-42af-4e8e-89e2-032177dfe9b5%40hemmecke.org.

Reply via email to