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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More data structures #1

Open
jwerle opened this issue Apr 2, 2020 · 9 comments
Open

More data structures #1

jwerle opened this issue Apr 2, 2020 · 9 comments

Comments

@jwerle
Copy link
Member

jwerle commented Apr 2, 2020

I have a small list implementation here that we could port over

@aep
Copy link
Contributor

aep commented Apr 5, 2020

sure, open a PR please

@aep
Copy link
Contributor

aep commented Apr 5, 2020

looks like its heap allocated. std is heap free, since zz's main goal is to be usable for systems without dynamic memory.

@aep
Copy link
Contributor

aep commented Apr 5, 2020

For good design on heapless data structures look at japarics heapless. I asked for the publication which hopefully has more things to learn from. rust-embedded/heapless#146

@aep
Copy link
Contributor

aep commented Apr 5, 2020

@aep aep changed the title list module More data structures Apr 5, 2020
@jwerle
Copy link
Member Author

jwerle commented Apr 5, 2020

This is a great read. Thank you. I'll remove heap allocations today! I think the ergonomics of the list will be pretty straightforward for stack allocations:

new+16 mut list = zxlist::init(); // a list that can container 16 items
list.rpush("hello");
list.rpop(); // "hello" 

I've noticed your usage of make() for constructor functions. Is that the convention that should be followed? I'll convert my init() constructors to make() if so

@aep
Copy link
Contributor

aep commented Apr 5, 2020

yep, that api looks good.

note zetzit/zz#53. for discussion on generic list types.

convention for constructors is that it needs to take a new self pointer, that is "Type mut new*self".
new doesnt mean anything yet, but if you dont add it, it'll break later when i finish memory initialization trackin.

there's no convention for the function name. you could have multiple constructors that construct different states, like default, none, etc. Think of it as "what state is the type in after the constructor is called"

@aep
Copy link
Contributor

aep commented Apr 5, 2020

i wonder if @richfelker would have more reading material on designing heapless data structures.
Rich does incredibly readable C code, so any input would be appreciated.

@jwerle
Copy link
Member Author

jwerle commented Apr 5, 2020

great, I pushed a refactor over here and using it over here checkout zetzit/zz#53 now

@aep
Copy link
Contributor

aep commented Aug 26, 2020

sized void should make this possible now

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

No branches or pull requests

2 participants