Commit 6f17c43
committed
refactor(Collections): improve ArrayList and LinkedList implementations
This commit enhances both ArrayList and LinkedList classes to provide
better key handling, consistent exception throwing, and support for
mixed key types. It improves type safety, performance, and API consistency.
ArrayList changes:
- Add isValidArrayKey method for key validation (int or string)
- Update set method to throw exceptions for invalid keys and out-of-range indices
- Modify hasKey method to use isValidArrayKey and array_key_exists
- Update get method to use the new hasKey implementation
- Add keyToString method for better error messages
- Simplify contains method using in_array for better performance
LinkedList changes:
- Modify set and get methods to support mixed key types
- Implement findNode method to locate nodes by index or value
- Add compareValues method for flexible element comparison
- Update exception messages to include key information
- Ensure consistent behavior between numeric and non-numeric keys
General:
- Update method signatures to use mixed type consistently across both classes
- Improve code comments and method descriptions1 parent 8cc515e commit 6f17c43
File tree
5 files changed
+6227
-6168
lines changed- src/Collection
5 files changed
+6227
-6168
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
0 commit comments