-
Notifications
You must be signed in to change notification settings - Fork 103
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
refactor: @immut/array.make and @immut/array.makei #1765
base: main
Are you sure you want to change the base?
refactor: @immut/array.make and @immut/array.makei #1765
Conversation
a1e7fcb
to
0ed43d5
Compare
Pull Request Test Coverage Report for Build 5695Details
💛 - Coveralls |
Array::make(quot, FixedArray::make(branching_factor, value)) | ||
} else { | ||
let arr : Array[FixedArray[A]] = Array::make(quot + 1, []) | ||
for k in 0..<quot { | ||
arr[k] = FixedArray::make(branching_factor, value) | ||
} |
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.
Is the alias here expected (using Array::make
)? If yes, should it apply to the second arr
too?
let arr : Array[FixedArray[A]] = Array::make(quot + 1, FixedArray::make(branching_factor, value))
arr[quot] = FixedArray::make(rem, value)
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 there is another optimization that can be done: since the leaves won't get modified by themselves while having the same content, we can just do
let leaf = FixedArray::make(branching_factor, value)
let arr : Array[FixedArray[A]] = Array::make(quot + 1, leaf)
avoid use closure
0ed43d5
to
44a720a
Compare
The pull request aims to simplify the implementation of 💡 [Improvement in code clarity and simplicity]
|
Array::make(quot, FixedArray::make(branching_factor, value)) | ||
} else { | ||
let arr : Array[FixedArray[A]] = Array::make(quot + 1, []) | ||
for k in 0..<quot { | ||
arr[k] = FixedArray::make(branching_factor, value) | ||
} |
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 there is another optimization that can be done: since the leaves won't get modified by themselves while having the same content, we can just do
let leaf = FixedArray::make(branching_factor, value)
let arr : Array[FixedArray[A]] = Array::make(quot + 1, leaf)
fn tree(cap, len, s) -> Tree[A] { | ||
if cap == branching_factor { | ||
Leaf(gen_leaf(s, len)) | ||
fn from_leaves[A](leaves : ArrayView[FixedArray[A]], cap : Int) -> Tree[A] { |
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.
To my understanding, given a list of leaves, this function constructs the tree top-down. It causes a from_leaves
call for every tree node. A more efficient way is to do it bottom-up, building the tree layer by layer. But it is just a suggestion for improvement, it is okay to leave it this way. I can update it later.
avoid use closure
And this implementation will be a bit simpler than the previous new_by_leaves, and can also be reused by from_iter