https://github.com/tornikegomareli/deque
🦸♂️A Deque collection type implemented with Swift's protocols: Sequence, Collection, MutableCollection, and BidirectionalCollection with using of circular buffer to maximize memory usage
https://github.com/tornikegomareli/deque
circular-buffer collection-protocol data-structures deque swift
Last synced: about 2 months ago
JSON representation
🦸♂️A Deque collection type implemented with Swift's protocols: Sequence, Collection, MutableCollection, and BidirectionalCollection with using of circular buffer to maximize memory usage
- Host: GitHub
- URL: https://github.com/tornikegomareli/deque
- Owner: tornikegomareli
- Created: 2023-04-09T22:51:19.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-10T00:03:07.000Z (over 2 years ago)
- Last Synced: 2025-07-08T22:45:01.771Z (3 months ago)
- Topics: circular-buffer, collection-protocol, data-structures, deque, swift
- Language: Swift
- Homepage:
- Size: 18.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
![]()
Using a circular buffer as storage, the Deque custom collection type in Swift offers a double-ended queue data structure. At both ends of the queue, it enables efficient insertion and removal operations.
This implementation still requires some performance optimizations, such as lazy resizing and the use of a custom index type to prevent pointless range checks. Although I believe it is enough for my Medium article, which is the reason for this, and data structure is doing its job in this context, I may add more improvements in the future, solely for educational uses.
Please refrain from using this data structure in your projects as it is a long way from being ready for production.
## Usage
To use Deque in your project, simply install it with SPM. Then, you can create a new instance of Deque with the desired capacity
```swift
var deque = Deque(capacity: 10)
deque.prepend(1)
deque.append(1)
deque.removeLast()
deque.removeFirst()
```You can then use the append, prepend, removeFirst, and removeLast methods to add and remove elements from the deque.
Deque also conforms to the Collection protocol and Sequence Protocol, so you can use it in any context that expects a collection or Sequence.
## Contributing
This implementation is for educational purposes and created for an article. However, if you find any bugs or have any suggestions for improvements, feel free to submit an issue or pull request.