Am So., 11. Okt. 2020 um 10:20 Uhr schrieb Marc Nieper-Wißkirchen <marc.nieper+...@gmail.com>: > > Am So., 11. Okt. 2020 um 03:28 Uhr schrieb Bruno Haible <br...@clisp.org>:
[...] > > * hamt_lookup: If the caller is allowed to modify the payload stored in the > > returned entry, this function should return a 'Hamt_entry *', not a > > 'const Hamt_entry *'. Just like 'strchr' and 'strstr' return a 'char *', > > not a 'const char *'. > > Unless the caller knows what it does, modifying the payload is not a > good idea because the entry is shared between different hamts. If the > caller really wants to modify the payload, it has to do an explicit > type cast (which is safe). I have noticed a problem with the current design: While an element can be in more than one hamt (because copies of hamts are created through various operations), an element cannot be actively inserted in more than one hamt. The reason is that the reference counter of the element is initialized whenever the element is inserted. The way out is to expose the initialization function to the user, who becomes responsible for initializing each element exactly once. As soon as it is possible to insert an element more than once, another observation will be made: The insert procedure does not accept a pointer to a const element because it must be able to change the reference counter internally. Thus it is more convenient if procedures like hamt_lookup do not return const versions.