JordiPolo
I am writing a library to deal with dataframes. Dataframes can be thought as excel tables. The main data is a 2D table and any operation can be row based or column based.
Operations include filtering by column, row, adding or deleting rows, columns, etc.
Right now, in a very naive way, I’ve implemented the main data as a list of lists, row based. But of course this makes column operations expensive (add a new element in a certain position to each list for instance).
If I switch to list of list, column based, then row operations would be expensive.
Tuples would not make it I believe because they may get huge and there may be lots of modifications
and Maps are not ordered, and I need order.
Any advise? Are out there any comparison of performance of each of the Elixir data structures?
Trending in Discussions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
benwilson512
People very frequently use maps where the key is a tuple of coordinates, and the value is the value at that coordinate. IE:
JordiPolo
Sounds good but I think in my case would only make sense if it is fast to get all the keys for a given row or column.
in your example:
I’d possible like to get all the elements in column 1, for instance, ideally something like:
But it does not seem to be possible, it says _ is an unbound variable.
NobbZ
Extracting a single row or column I think is most efficient by using
Enum.filter/2. This would make extracting a single column or row O(row * colums) though.If you really need O(1) access to a complete row or column randomly, I do think, that a doubled DS would be the only thing to go, but it does double the amount of memory needed to hold the structure, also it makes writes expensive since they had to be done twice.
Basically you need to two nested maps
%{row_id => %{col_id => data_sample}}and%{col_id => %{row_id => data_sample}}.benwilson512
Yeah the duplication is definitely a possibility. Fortunately this is less duplication than it may look at first glance because cell values are just pointed to by each map location, not actually duplicated.
:etscould be another possibility because it does support a{_, 1}style match operation.FWIW even traditional mutable 2d arrays suffer from this question. If you make row access primary then column access requires large jumps in memory which eats away at any cache locality you may have gotten with row access.
dimitarvp
Okay, maybe I am not getting something very important here, but are you not, in essence, needing a simple two-dimensional array?
NobbZ
You probably are missing that there are no arrays in elixir.
dimitarvp
But there are tuples with arbitrary sizes. And you have native functions to deal with them.
My point was that you could simulate any dimension of array in the single-dimensional tuple. I understand it’s not practical for changing data however.
benwilson512
Tuples must be wholly copied on every update. The OP mentioned that updates are common which generally disqualifies large tuples.
dimitarvp
Yep. Seems like a managed data structure is in order. Probably list (or tuple) of tuples with a maximum size (probably 64).
Sorry that I can’t be more helpful.
OvermindDL1
The erlang
:arraymodule already does that tuple managing for very fast row access. I’d say use it, it is well tested.For note, maps are ‘almost’ on par with
:arrayin speed in almost all cases (sometimes even a bit faster) except iteration, which sounds like it might be something you need.Overall though I’d say use maps, and if you setup your key just right then iteration can be very fast too.