Skip to content

Conversation

@mohameds-dev
Copy link
Owner

Release new features and refactor code for simplicity and readability

New features

  • move_to_back method on map: allows moving entries to the end of the map in O(1) without copying the value
  • Decrement operator on list and map iterators to go in reverse iteration direction (--it and it--)
  • clear and empty methods in map

All features were developed with TDD

Refactor

  • Move public constructors and methods to be at the very top of the class to boost readability
  • Move private fields to the very bottom of the classes
  • Extract common checking logic in list in a private helper function to reduce code duplication

- Substitute repetitive push_backs with initializer list to make tests simpler and easier to read
- Create tests for edge cases when using ++ and -- on empty list
- Make the tests pass by modifying the list iterator code
- Dereferencing end iterator
- Dereferencing begin iterator on empty list
- Post and pre decrement operator functionality
- Create tests for dereferencing and copying iterators
- Create tests for edge cases when incrementing or decrementing out of range
- Simplify tests by using initializer lists and constructors using iterators
- Move private fields to the end
- Move private internal methods below public ones
- Make empty() rely on head ptr
- Make clear() rely on empty()
- Use empty() to express intent when checked
- Create tests for using pre-decrement (--iterator) on begin iterator in both empty & non-empty lists
- Make the tests pass by adding a check to raise exception if it's called on begin iterator
- Create tests for erase functionality in map
- Create DestructionFlag to flag calling destructor on values when entries are erased
- Add a destruction flag test for clear method as well
@mohameds-dev
Copy link
Owner Author

looks good to me

@mohameds-dev mohameds-dev merged commit 347898a into main May 28, 2025
1 check passed
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.

2 participants