zetzit / nursery

zz module repository for modules not yet in std
3 stars 1 forks source link

More data structures #1

Open jwerle opened 4 years ago

jwerle commented 4 years ago

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

aep commented 4 years ago

sure, open a PR please

aep commented 4 years ago

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

aep commented 4 years ago

For good design on heapless data structures look at japarics heapless. I asked for the publication which hopefully has more things to learn from. https://github.com/japaric/heapless/issues/146

aep commented 4 years ago

Stuff @whitequark does is also interesting to read

https://lab.whitequark.org/notes/2016-12-17/owning-collections-in-heap-less-rust/

jwerle commented 4 years ago

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 commented 4 years ago

yep, that api looks good.

note https://github.com/zetzit/zz/issues/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 commented 4 years ago

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 commented 4 years ago

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

aep commented 4 years ago

sized void should make this possible now