Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayList iterator, unifying API of HashMap and its derivatives #981

Merged
merged 1 commit into from May 4, 2018
Merged

ArrayList iterator, unifying API of HashMap and its derivatives #981

merged 1 commit into from May 4, 2018

Conversation

BraedonWooding
Copy link
Contributor

This PR just does a small little unification; adding 'count' function to hashmap, arraylist, bufmap, and bufset (which just returns the inner storage value), this is more intended for as we extend the amount of data structures it is nice to have a set of API functions to follow for example having a 'count' function and so on, this makes it easier for library builders to utilise duck typing and support multiple collections in their libraries 馃槃.

Secondly it adds an iterator to ArrayList, again for the above reason. All iterators also have a reset function attached.

Motivation

Again to bring up my Lazy library, I support you doing queries on slices such as Lazy.init(slice[0..]).where(odd).select(pow).toArray(buf[0..]), and when I wanted to extend it to supporting ArrayLists and Hashmaps I found a problem, they had conflicting APIs (and ArrayList had no iterator), so overall this fixes that by providing a consistent API.


pub fn next(it: &Iterator) ?T {
if (it.count >= it.list.len) return null;
const val = it.list.at(it.count);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrewrk Currently this seems like the best way to do it? Though I think I could also just index the .items property since I do check bounds.

@@ -174,4 +228,4 @@ test "insert ArrayList test" {
const items = []const i32 { 1 };
try list.insertSlice(0, items[0..0]);
assert(list.items[0] == 5);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newlines were removed from the end of all the files you modified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't remember having them be part of a standard, if they are I'll add them back; just my visual studio code having its own mind :).

@andrewrk andrewrk merged commit 33fa87a into ziglang:master May 4, 2018
@andrewrk
Copy link
Member

andrewrk commented May 4, 2018

Thanks! Looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants