Questions on using or implementing more or less common data structures such as linked lists, structs, trees, tries, heaps etc. in Mathematica.

learn more… | top users | synonyms

75
votes
7answers
7k views

Struct equivalent in Mathematica?

I really miss having something like a struct in Mathematica. I know of (and regularly use) a couple of programming techniques which feel like a ...
43
votes
2answers
2k views

What is a Mathematica packed array?

A simple sounding question with a few sub questions: What is the difference between unpacked vs packed array? Are packed arrays more space efficent, how much so? Are packed arrays more time ...
77
votes
1answer
3k views

File-backed lists/variables for handling large data

Background Currently I am working with some large data (most of it generated by Mathematica itself). I usually find it a hassle to do this. For example, I just exported a large amount of data to ...
42
votes
2answers
9k views

How can I use Mathematica's graph functions to cheat at Boggle?

This question is inspired by a Stack Overflow question that I decided to solve using Mathematica. In addition to Mathematica, I thought I'd use some of the new version's graph-related functionality, ...
25
votes
2answers
786 views

Can a Trie be implemented efficiently?

What is the most space and time efficient way to implement a Trie in Mathematica? Will it be practically faster than what is natively available in appropriate cases?
13
votes
2answers
599 views

Question about designing a particular data structure

Background: I store polygons with a color assigned at the face level. In some occasions I want to use vertex colors but I want to store data efficiently, i.e. don't want to duplicate data to the ...
8
votes
2answers
394 views

How to get the list of defined values for an indexed variable?

I would like a table with rational indexes - thus it would be practical to use a dictionary, which, in Mathematica are implemented with the indexed variables. I would like to be able to do: ...
21
votes
3answers
800 views

Emulating R data frame getters with UpValues

What's the best way to emulate R's data frames functionality? This includes the ability to select rows and columns in a 2-dimensional table by the string identifiers positioned typically in the first ...
23
votes
4answers
1k views

How to create strong types?

In a program I'm writing, I create a list of lists, that looks something like this: {{100, {1,2,3,4,5}}, {105, {2,4,6,8}}, {42, {42,39,56}}} I then pass this ...
13
votes
4answers
377 views

Short syntax for accessing System`Utilities`HashTableAdd and System`Utilities`HashTableGet

I have a need for a struct analogue in Mathematica. After reading this post I came to the conclusion that System`Utilities`HashTable is one of the best options. But ...
18
votes
3answers
420 views

Error changing Dataset using Part

In the new guide Computation With Structured Datasets we can find this part, on how to change a Dataset But if we create a Dataset like: ...
2
votes
3answers
274 views

Re-arranging / selecting of a data table very slow in For loop [duplicate]

My task is quite simple; I have a table of data like M = {{1,2}, {1,3}, {3,4}, {5,1}, {6,9}, {6,8}, {6,1}}; so the table is sorted with respect to the first ...
19
votes
4answers
556 views

How can a big table be treated as a database?

I often work with big tables that I want to treat kind of like a database. Here's an example table. ...
20
votes
2answers
842 views

How can one define a custom data object?

In Mathematica there are different objects like InterpolatingFunction or SparseArray? How can I define a custom data object with ...
19
votes
2answers
642 views

How can I add a column into a existing Dataset?

I'm very excited about the brand new Dataset function. I have played with it in Wolfram Cloud, and haven't figured out how can I add a new column into an existing ...
12
votes
3answers
432 views

Using Memoization with a Mutable Object

In looking for a solution to this question, I ran across some old binary tree code by Daniel Lichtblau, reproduced below: ...
11
votes
3answers
2k views

Implementing a dictionary data structure

As one learns from a course on data structures, hash maps or dictionaries can be efficient when applied to appropriate tasks. I need a hash map in Mathematica and I've never found it. I'm scratching ...
6
votes
1answer
238 views

Return a Part by Reference? (For accessing hierarchical / structured data)

Is there a way to return a part of a list by reference, for reading and writing? I want to do this so I can easily manipulate "rule-styled structured", i.e., hierarchical data that is loaded from a ...
5
votes
1answer
184 views

Converting hierarchies of rules to associations

The impossibility of MatchQ-ing inside and Association MatchQ-ing Associations (MMA 10) explains a problem I have. I would like ...
8
votes
2answers
232 views

Cases[data,Colon[key,_]] vs. Cases[data,key:_] toward XPath, XQuery

Exploring methods to index and search tree-structured key:value pairs via named-entity index (key paths) as opposed to Position-based indexing. Using Rule as ...
20
votes
4answers
718 views

Efficient circular buffer?

I wish to create an efficient circular buffer. That is, I wish to keep a fixed length list while appending a new value and dropping the oldest, repeatedly. As we know lists in Mathematica are ...
14
votes
1answer
451 views

Creating a R DataFrame like construct in Mathematica

I kept getting my data mixed up so I decided to see if I could construct a package adding a R DataFrame like construct to Mathematica. I managed to cobble something together that sort of works, but ...
14
votes
1answer
485 views

Efficient code for tallying entries in very large lists

I am dealing with data sets containing tens of millions of (hashable) entries and simply using the Tally function to count the frequency of each unique list element ...
12
votes
3answers
2k views

Excel Headers --> Mathematica

I have a large Excel .xls file. Miniature version shown below: (formatting should appear as two columns...) ...
16
votes
3answers
452 views

How to get complete Documentation Center graph of guide pages?

On the very last image below you can see a typical path of walking through Documentation Center guide pages. What is the best way to get the graph data and visualize the whole structure of these ...
14
votes
2answers
416 views

Efficient priority queues?

I'm trying to figure out how to transfer the concept of a priority queue to the functional world. Searches have turned up some implementations that use Append and other expense list copying ...
10
votes
1answer
203 views

Is there a method to enumerate the keys/values of System`Utilities`HashTable

Lacking from the simple API of System`Utilities`HashTable is a method to enumerate the keys/values. ...
6
votes
2answers
330 views
4
votes
2answers
251 views

Access pairs of vectors, rather than the matrices, in partitioned data structure at a levelspec

I have some old code to analyze correlation between 2 time series by looking at windows of different lengths shifting across the time series data. The code: gets 2 sets of time series data (in ...
1
vote
0answers
245 views

Data structure for a list of actions

The idea: I need to generate a sequence of events then run a "propagator" over the list of events where the "propagator" will update the state of the following event. I can then write functions that ...
1
vote
1answer
579 views

pointer like operations in mathematica and evaluation control

I would like to create a data structure of the type "header[pointer]" where pointer would point to a list. I will shown on an example how I'd like this to work, and where the problems are. ...
8
votes
1answer
115 views

Why won't SparseArray let me store values with the head List?

When you attempt to define a SparseArray with elements that have the head List it complains: ...
4
votes
2answers
320 views

What is the Mathematica way of joining two tables?

Is there a special Mathematica way of joining tables of data together, so that I would get similar functionality as if I was running a database with sql? For example, I have one particular table ...
2
votes
2answers
367 views

Get positions of all non zero matrix elements

I want to find all non zero elements of a table and I want to create a list that contains the name of the table the element was removed from, the position of the element, and the value of the element. ...