-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow other int types for type container size #893
Merged
oxinabox
merged 4 commits into
JuliaCollections:master
from
KronosTheLate:allow_other_int_types_for_type_container_size
Jan 30, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ docs/site/ | |
docs/Manifest.toml | ||
Manifest.toml | ||
benchmark/*.json | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -19,18 +19,21 @@ | |||||||
len <= length(buf) || throw(ArgumentError("Value of 'length' must be <= length of buffer")) | ||||||||
return new{T}(length(buf), f, len, buf) | ||||||||
end | ||||||||
|
||||||||
# Convert any `Integer` to whatever `Int` is on the relevant machine | ||||||||
CircularBuffer{T}(f::Integer, len::Integer, buf::Integer) where {T} = CircularBuffer{T}(Int(f), Int(len), Int(buf)) | ||||||||
Comment on lines
+22
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per above i don't think this is needed since constructors automatically convert.
Suggested change
|
||||||||
end | ||||||||
|
||||||||
function CircularBuffer{T}(iter, capacity::Int) where {T} | ||||||||
function CircularBuffer{T}(iter, capacity::Integer) where {T} | ||||||||
vec = copyto!(Vector{T}(undef,capacity), iter) | ||||||||
CircularBuffer{T}(1, length(iter),vec) | ||||||||
end | ||||||||
|
||||||||
CircularBuffer(capacity::Int) = CircularBuffer{Any}(capacity) | ||||||||
CircularBuffer(capacity::Integer) = CircularBuffer{Any}(capacity) | ||||||||
|
||||||||
CircularBuffer{T}(capacity::Int) where {T} = CircularBuffer{T}(T[],capacity) | ||||||||
CircularBuffer{T}(capacity::Integer) where {T} = CircularBuffer{T}(T[],capacity) | ||||||||
|
||||||||
CircularBuffer(iter,capacity::Int) = CircularBuffer{eltype(iter)}(iter,capacity) | ||||||||
CircularBuffer(iter,capacity::Integer) = CircularBuffer{eltype(iter)}(iter,capacity) | ||||||||
|
||||||||
function CircularBuffer{T}(iter) where {T} | ||||||||
vec = reshape(collect(T,iter),:) | ||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -20,13 +20,16 @@ mutable struct DequeBlock{T} | |||||||
blk.next = blk | ||||||||
return blk | ||||||||
end | ||||||||
|
||||||||
# Convert any `Integer` to whatever `Int` is on the relevant machine | ||||||||
DequeBlock{T}(capa::Integer, front::Integer) where T = DequeBlock{T}(Int(capa), Int(front)) | ||||||||
Comment on lines
+23
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per above
Suggested change
|
||||||||
end | ||||||||
|
||||||||
# block at the rear of the chain, elements towards the front | ||||||||
rear_deque_block(ty::Type{T}, n::Int) where {T} = DequeBlock{T}(n, 1) | ||||||||
rear_deque_block(ty::Type{T}, n::Integer) where {T} = DequeBlock{T}(n, 1) | ||||||||
|
||||||||
# block at the head of the train, elements towards the back | ||||||||
head_deque_block(ty::Type{T}, n::Int) where {T} = DequeBlock{T}(n, n+1) | ||||||||
head_deque_block(ty::Type{T}, n::Integer) where {T} = DequeBlock{T}(n, n+1) | ||||||||
|
||||||||
capacity(blk::DequeBlock) = blk.capa | ||||||||
Base.length(blk::DequeBlock) = blk.back - blk.front + 1 | ||||||||
|
@@ -37,7 +40,7 @@ isrear(blk::DequeBlock) = blk.next === blk | |||||||
|
||||||||
# reset the block to empty, and position | ||||||||
|
||||||||
function reset!(blk::DequeBlock{T}, front::Int) where T | ||||||||
function reset!(blk::DequeBlock{T}, front::Integer) where T | ||||||||
empty!(blk.data) | ||||||||
resize!(blk.data, blk.capa) | ||||||||
blk.front = front | ||||||||
|
@@ -80,7 +83,7 @@ mutable struct Deque{T} | |||||||
head::DequeBlock{T} | ||||||||
rear::DequeBlock{T} | ||||||||
|
||||||||
function Deque{T}(blksize::Int) where T | ||||||||
function Deque{T}(blksize::Integer) where T | ||||||||
head = rear = rear_deque_block(T, blksize) | ||||||||
new{T}(1, blksize, 0, head, rear) | ||||||||
end | ||||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can just do
since constructors automatically call
convert
on all arguments.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I though about that option, but it somehow seemed more clear to me to explicitly do what will happen automatically. It somehow makes the code more readable to me, because it shows it's purpose more clearly. But I do not have strong opinions, so if you prefer this, it is fine by me ^_^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point (getting rid of this behavour has actually been talked about for julia 2.0).
On the other hand, code that doesn't exist can't have bugs.