Skip to content

Hash_map: Implement erase method.#6493

Closed
GilesBathgate wants to merge 10 commits intoCGAL:mainfrom
GilesBathgate:Hash_map-erase-GilesBathgate
Closed

Hash_map: Implement erase method.#6493
GilesBathgate wants to merge 10 commits intoCGAL:mainfrom
GilesBathgate:Hash_map-erase-GilesBathgate

Conversation

@GilesBathgate
Copy link
Copy Markdown
Contributor

@GilesBathgate GilesBathgate commented Apr 15, 2022

Summary of Changes

When looking at SNC_structure from the Nef_3 package, I noticed an unusual design that wraps Object_iterator in a boost::optional I have come to believe that the reason for the design is to work around the fact that Unique_hash_map/chained_map implementation does not support an erase function. Instead of removing the Object_iterator from the hashmap, its optional wrapper is set to boost::none. In theory, this design could have a memory leak, as adding and removing boundary items would only add optional items. I am not sure if this is the case in practice.

Either way, I decided to attempt to implement erase for the hashmap. One of the problems that I ran into was managing the so-called free pointer since the existing code needs to be able to increment it to move to the next available memory, but the erased element could exist below the free pointer's location. One approach would be to move the erased element to the location of the free pointer and decrement the free pointer, but this was found to be slow, as it required unlinking anything that pointed to the free node.

Instead, I had the idea of a "free chain" which builds on the single linked lists of the existing code. I think this idea could be novel, but I am not very well versed in hashmap literature. Essentially the idea is to build a chain of the overflow memory, and instead of incrementing free, an iterator function free = free->succ is used. The advantage of this approach is that when memory needs to be returned to the overflow memory via erase, it is simply a case of inserting it back into the free chain.

The pull request also adds a contains method (wrapper for is_defined) and uses the methods within SNC_structure/Sphere_map. Usage of std::move was added to erase and rehash.

Testing

  • Nef_3 ctest 100% pass
  • Nef_S2 ctest 100% pass
  • Hash_map ctest 100% pass

Release Management

  • Affected package(s): Hash_map
  • Issue(s) solved (if any): cleaning
  • License and copyright ownership: Returned to CGAL authors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant