Add thread-safe queue implementation#7388
Conversation
Issue TheAlgorithms#7356: Add null check for the search value to prevent potential NullPointerException.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7388 +/- ##
============================================
- Coverage 79.45% 79.37% -0.09%
- Complexity 7083 7179 +96
============================================
Files 790 799 +9
Lines 23164 23521 +357
Branches 4556 4623 +67
============================================
+ Hits 18405 18669 +264
- Misses 4022 4108 +86
- Partials 737 744 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Nice work on the implementation! I was planning to start working on this after opening the issue, but great to see it already in progress. If you're okay with it, I can contribute by adding test cases to strengthen the PR. |
|
Nice work! 🎯 |
|
Hey @Senrian, I can add the test cases for this PR. The existing tests have an issue — assertNull on dequeue() will fail since implementation throws NoSuchElementException. I have improved tests ready with thread safety coverage. |
Description
Adds a simple thread-safe queue implementation (
ThreadSafeQueue) to the data structures directory.This implementation uses the
synchronizedkeyword on methods to ensure thread safety, as requested in issue #7387.Features:
synchronizedkeywordenqueue,dequeue,peek,isEmpty,sizeIterable<T>for enhanced usabilityImplementation details:
Node<T>class for linked list nodesNoSuchElementExceptionwhen dequeuing/peeking from empty queueIllegalArgumentExceptionwhen enqueueing null dataFixes #7387
Type of Change
Checklist: