JordiPolo

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?

Showing Posts 1 to 10

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

People very frequently use maps where the key is a tuple of coordinates, and the value is the value at that coordinate. IE:

%{
  {0, 0} => 1,
  {0, 1} => 2,
}
JordiPolo

JordiPolo OP

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:

%{
{0, 0} => 1,
{0, 1} => 2,
}

I’d possible like to get all the elements in column 1, for instance, ideally something like:

Map.get(map, {_, 1})

But it does not seem to be possible, it says _ is an unbound variable.

NobbZ

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

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

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.

:ets could 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

dimitarvp

Okay, maybe I am not getting something very important here, but are you not, in essence, needing a simple two-dimensional array?

NobbZ

NobbZ

You probably are missing that there are no arrays in elixir.

dimitarvp

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. :unamused:

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Tuples must be wholly copied on every update. The OP mentioned that updates are common which generally disqualifies large tuples.

dimitarvp

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

OvermindDL1

The erlang :array module 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 :array in 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.

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
maennchen
:warning: Security advisory: Decimal DoS vulnerability A vulnerability has been published for decimal where very large exponents can cau...
New
marciol
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New

Other Trending Topics Top

marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews