# \#data\_structures

**URL:** https://discourse.julialang.org/tag/data-structures/213.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Using type parameters in the types of the fields](https://discourse.julialang.org/t/using-type-parameters-in-the-types-of-the-fields/138790)

<div class="topic-metadata">

**Author:** [@rokke](https://discourse.julialang.org/u/rokke)\
**Replies:** 16\
**Last updated:** [August 20, 2026, 5:48am UTC](https://discourse.julialang.org/t/using-type-parameters-in-the-types-of-the-fields/138790 "2026-08-20T05:48:43Z")

</div>

I’m not a data structures person, so the right answer here might be “you’re doing it wrong, try this instead”; but I’ll start with the immediate question I have: in a recursive type, is it not possible to have the type …

---

## [Keep n largest values compared by f](https://discourse.julialang.org/t/keep-n-largest-values-compared-by-f/137699)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 5\
**Last updated:** [June 19, 2026, 5:04pm UTC](https://discourse.julialang.org/t/keep-n-largest-values-compared-by-f/137699 "2026-06-19T17:04:31Z")

</div>

I am iterating through about 10^6 values x and want to keep n of those for which f(x) is the largest.n is around 1000. I have looked at similar topics (1, 2, 3), some suggest maintaining a vector (see below), some min-m…

---

## [Dataframe data manipulation](https://discourse.julialang.org/t/dataframe-data-manipulation/136950)

<div class="topic-metadata">

**Author:** [@SergeantMike67](https://discourse.julialang.org/u/SergeantMike67)\
**Replies:** 7\
**Last updated:** [June 4, 2026, 3:48pm UTC](https://discourse.julialang.org/t/dataframe-data-manipulation/136950 "2026-06-04T15:48:45Z")

</div>

I have a data frame that is formatted like the example below. Row │ Pairwise p\_adj boo Factor IntBoo │ String Float64 Bool String …

---

## [Passing arguments separately versus packing them into a struct](https://discourse.julialang.org/t/passing-arguments-separately-versus-packing-them-into-a-struct/132291)

<div class="topic-metadata">

**Author:** [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Replies:** 5\
**Last updated:** [September 12, 2025, 1:38am UTC](https://discourse.julialang.org/t/passing-arguments-separately-versus-packing-them-into-a-struct/132291 "2025-09-12T01:38:09Z")

</div>

I regularly have a large number of arguments to carry around, where each of the arguments has a concrete type, but where the concrete types can be different (multiple dispatch). The arguments are typically more complica…

---

## [Fix parameter when passing to optimizer](https://discourse.julialang.org/t/fix-parameter-when-passing-to-optimizer/61102)

<div class="topic-metadata">

**Author:** [@misha\_mikhasenko](https://discourse.julialang.org/u/misha_mikhasenko)\
**Replies:** 26\
**Last updated:** [April 12, 2025, 3:16pm UTC](https://discourse.julialang.org/t/fix-parameter-when-passing-to-optimizer/61102 "2025-04-12T15:16:23Z")

</div>

When doing the optimization step, I often want to fix some parameters of the model. With parameters being a NamedTuple, or ComponentArray, my current solution is to split to organized two sets of parameters (free and fi…

---

## [Dict with integer keys and fastest insertion?](https://discourse.julialang.org/t/dict-with-integer-keys-and-fastest-insertion/125171)

<div class="topic-metadata">

**Author:** [@Leo\_I](https://discourse.julialang.org/u/Leo_I)\
**Replies:** 8\
**Last updated:** [January 25, 2025, 1:28pm UTC](https://discourse.julialang.org/t/dict-with-integer-keys-and-fastest-insertion/125171 "2025-01-25T13:28:35Z")

</div>

What are the best options for a dict/map with integer keys and the fastest insert/update? For background, I wish to aggregate those position-weight pairs (p,w) where the position is the same, I’m tinkering with the idea …

---

## [How to define a Julia Vector with only integers ≥ 0](https://discourse.julialang.org/t/how-to-define-a-julia-vector-with-only-integers-0/120894)

<div class="topic-metadata">

**Author:** [@Brinkhuis](https://discourse.julialang.org/u/Brinkhuis)\
**Replies:** 3\
**Last updated:** [October 5, 2024, 4:18am UTC](https://discourse.julialang.org/t/how-to-define-a-julia-vector-with-only-integers-0/120894 "2024-10-05T04:18:30Z")

</div>

As input for a function, I need a Vector with values greater than or equal to zero. I tried l = Array{\>:UInt8, 1} However push!(l, 9) throws an error. MethodError: no method matching push!(::Type{Vector{\>:UInt8}}, ::I…

---

## [Persistent vertex identities for Steiner tree, vertex removal](https://discourse.julialang.org/t/persistent-vertex-identities-for-steiner-tree-vertex-removal/119568)

<div class="topic-metadata">

**Author:** [@bremez](https://discourse.julialang.org/u/bremez)\
**Replies:** 7\
**Last updated:** [September 20, 2024, 2:32pm UTC](https://discourse.julialang.org/t/persistent-vertex-identities-for-steiner-tree-vertex-removal/119568 "2024-09-20T14:32:39Z")

</div>

I have a use case for a large graph, from which I iteratively remove vertices, and at each step compute some Steiner trees from its current state. Specifically, my use case requires to know to which vertices in the origi…

---

## [Data Structures for Finite Volumes](https://discourse.julialang.org/t/data-structures-for-finite-volumes/119558)

<div class="topic-metadata">

**Author:** [@afleming](https://discourse.julialang.org/u/afleming)\
**Replies:** 3\
**Last updated:** [September 19, 2024, 6:09am UTC](https://discourse.julialang.org/t/data-structures-for-finite-volumes/119558 "2024-09-19T06:09:29Z")

</div>

I’m working on a (not very sophisticated) finite volume solver for my research, and I’ve run into a perplexing problem around storing the mesh in such a way that minimizes allocations. The basic idea is that every cell …

---

## [How do I code a simple linked list using DataStructures.jl](https://discourse.julialang.org/t/how-do-i-code-a-simple-linked-list-using-datastructures-jl/80929)

<div class="topic-metadata">

**Author:** [@ao222](https://discourse.julialang.org/u/ao222)\
**Replies:** 7\
**Last updated:** [October 23, 2022, 3:18pm UTC](https://discourse.julialang.org/t/how-do-i-code-a-simple-linked-list-using-datastructures-jl/80929 "2022-10-23T15:18:12Z")

</div>

Looking to code a linked list and add a cycle to the list so that I can implement the Floyd cycle detection algorithm. I found LinkedList from DataStructures.jl However I can’t figure out how to: create a list itera…

---

## [Compare data from two dataframes](https://discourse.julialang.org/t/compare-data-from-two-dataframes/118254)

<div class="topic-metadata">

**Author:** [@Sandy45](https://discourse.julialang.org/u/Sandy45)\
**Replies:** 3\
**Last updated:** [August 17, 2024, 1:57pm UTC](https://discourse.julialang.org/t/compare-data-from-two-dataframes/118254 "2024-08-17T13:57:45Z")

</div>

I have two dataframes as shown below and I need to create csv file or json output like shown below. I need to get dominant row for each product for each date from two dataframes then compare them to generate below outpu…

---

## [How to extend structs for equality, in order to make use of operator like \`in\`?](https://discourse.julialang.org/t/how-to-extend-structs-for-equality-in-order-to-make-use-of-operator-like-in/114322)

<div class="topic-metadata">

**Author:** [@BuddhiLW](https://discourse.julialang.org/u/BuddhiLW)\
**Replies:** 7\
**Last updated:** [May 16, 2024, 6:32pm UTC](https://discourse.julialang.org/t/how-to-extend-structs-for-equality-in-order-to-make-use-of-operator-like-in/114322 "2024-05-16T18:32:15Z")

</div>

I’m creating a package to run Black Jack simulations. I would like to write structs A, C2 (2-card), … etc for each card type in a deck. And, to have a general Card struct, so I can overload methods like +, ==, with Car…

---

## [\`Set\`s inside \`Set\`s = dangerous](https://discourse.julialang.org/t/set-s-inside-set-s-dangerous/113669)

<div class="topic-metadata">

**Author:** [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Replies:** 5\
**Last updated:** [April 30, 2024, 8:36pm UTC](https://discourse.julialang.org/t/set-s-inside-set-s-dangerous/113669 "2024-04-30T20:36:36Z")

</div>

A colleague discovered the following behaviour. I presume it’s known by those who know, but it doesn’t seem to be documented? julia\> s1 = Set{Int}(\[1\]); julia\> s2 = Set{Int}(\[1, 2\]); julia\> S = Set(\[s1, s2\]); …

---

## [Indexable set data structure](https://discourse.julialang.org/t/indexable-set-data-structure/112287)

<div class="topic-metadata">

**Author:** [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Replies:** 8\
**Last updated:** [April 2, 2024, 9:25am UTC](https://discourse.julialang.org/t/indexable-set-data-structure/112287 "2024-04-02T09:25:12Z")

</div>

I’m looking for a data structure that I’m sure must have already been invented and implemented, but which I can’t find (probably because I don’t know its canonical name). The data structure I have in mind shares some pr…

---

## [Swapping in a Binary Search Tree, and Leaf-Only Trees](https://discourse.julialang.org/t/swapping-in-a-binary-search-tree-and-leaf-only-trees/111839)

<div class="topic-metadata">

**Author:** [@narnold0](https://discourse.julialang.org/u/narnold0)\
**Replies:** 3\
**Last updated:** [March 20, 2024, 2:48pm UTC](https://discourse.julialang.org/t/swapping-in-a-binary-search-tree-and-leaf-only-trees/111839 "2024-03-20T14:48:42Z")

</div>

Hi there, I’m trying to implement the Bentley-Ottmann Algorithm in Julia. My problem is that I’ve only found out now that this Algorithm doesn’t utilize the normal implementation of a BST (AVL tree, RedBlack tree etc… f…

---

## [How to combine multiple SummaryStats objects into a single DataFrame?](https://discourse.julialang.org/t/how-to-combine-multiple-summarystats-objects-into-a-single-dataframe/108747)

<div class="topic-metadata">

**Author:** [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Replies:** 4\
**Last updated:** [January 12, 2024, 9:27pm UTC](https://discourse.julialang.org/t/how-to-combine-multiple-summarystats-objects-into-a-single-dataframe/108747 "2024-01-12T21:27:22Z")

</div>

I am apparently still missing some basic data manipulation skills. Is there a quick way to create a dataframe where the first row contains sx, and second row contains sy with the appropriate column names? julia\> using S…

---

## [Labeled vector or vector view of nested structure](https://discourse.julialang.org/t/labeled-vector-or-vector-view-of-nested-structure/108031)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 1\
**Last updated:** [December 25, 2023, 11:28am UTC](https://discourse.julialang.org/t/labeled-vector-or-vector-view-of-nested-structure/108031 "2023-12-25T11:28:38Z")

</div>

I am trying to organize a computation which maps a parameter vector p to various residuals r = f(p), and then solves for the root using a multivariate rootfinder. This part is simple. But then I want to understand and p…

---

## [What is the right way to store/record the results of this nested simulation?](https://discourse.julialang.org/t/what-is-the-right-way-to-store-record-the-results-of-this-nested-simulation/107639)

<div class="topic-metadata">

**Author:** [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Replies:** 8\
**Last updated:** [December 15, 2023, 4:25pm UTC](https://discourse.julialang.org/t/what-is-the-right-way-to-store-record-the-results-of-this-nested-simulation/107639 "2023-12-15T16:25:49Z")

</div>

I wrote this after seeing the responses to my last question. From the responses I can tell my problem was not understood. What this simulation does is play a rudimentary “game” between pairs of two teams once per “week…

---

## [How to best preallocate nested tuples of dataframes to store simulation results?](https://discourse.julialang.org/t/how-to-best-preallocate-nested-tuples-of-dataframes-to-store-simulation-results/107543)

<div class="topic-metadata">

**Author:** [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Replies:** 31\
**Last updated:** [December 14, 2023, 10:56pm UTC](https://discourse.julialang.org/t/how-to-best-preallocate-nested-tuples-of-dataframes-to-store-simulation-results/107543 "2023-12-14T22:56:13Z")

</div>

I’m trying to run some sport game simulations and programmatically store the results in the most efficient manner. Even if not strictly necessary for my purpose, I am trying to learn how to do right. Right now my order …

---

## [I want to use a PriorityQueue equivalent with duplicate keys](https://discourse.julialang.org/t/i-want-to-use-a-priorityqueue-equivalent-with-duplicate-keys/107534)

<div class="topic-metadata">

**Author:** [@Lee\_Phillips](https://discourse.julialang.org/u/Lee_Phillips)\
**Replies:** 4\
**Last updated:** [December 14, 2023, 2:09am UTC](https://discourse.julialang.org/t/i-want-to-use-a-priorityqueue-equivalent-with-duplicate-keys/107534 "2023-12-14T02:09:08Z")

</div>

Hey All I have some code pasted below making use of PriorityQueue from DataStructures package I’d like to store key value pairs in a sorted manner to easily retrieve the lowest key from the set. I need to be able to u…

---

## [Aliasing two structs and having them be subtypes of an abstract type?](https://discourse.julialang.org/t/aliasing-two-structs-and-having-them-be-subtypes-of-an-abstract-type/104410)

<div class="topic-metadata">

**Author:** [@linkz](https://discourse.julialang.org/u/linkz)\
**Replies:** 10\
**Last updated:** [October 2, 2023, 1:46pm UTC](https://discourse.julialang.org/t/aliasing-two-structs-and-having-them-be-subtypes-of-an-abstract-type/104410 "2023-10-02T13:46:10Z")

</div>

I am wondering if when I have two structs, say mutable struct A{a, b} str\_a::a str\_b::b end mutable struct B{a, b, c} str\_a::a str\_b::b str\_c::c end and I alias const A\_num = A{\<:Number} const B\_num = …

---

## [Enable all functions to work on element of new type](https://discourse.julialang.org/t/enable-all-functions-to-work-on-element-of-new-type/103210)

<div class="topic-metadata">

**Author:** [@s-baumann](https://discourse.julialang.org/u/s-baumann)\
**Replies:** 2\
**Last updated:** [August 25, 2023, 11:09pm UTC](https://discourse.julialang.org/t/enable-all-functions-to-work-on-element-of-new-type/103210 "2023-08-25T23:09:54Z")

</div>

If I make a new struct that contains a certain type (a DataFrame in below example) like: struct StructContainingDataFrame df::DataFrame something\_else::Any end Is it then possible to make this work with all fun…

---

## [Cache Data Structure for Lazy Array](https://discourse.julialang.org/t/cache-data-structure-for-lazy-array/102388)

<div class="topic-metadata">

**Author:** [@AlexanderNenninger](https://discourse.julialang.org/u/AlexanderNenninger)\
**Replies:** 5\
**Last updated:** [August 8, 2023, 9:28am UTC](https://discourse.julialang.org/t/cache-data-structure-for-lazy-array/102388 "2023-08-08T09:28:00Z")

</div>

I’ve got an implementation of a lazy array (lazyarrays.jl · GitHub), the entries of which are computed on the fly by function calls. From what we can tell it’s already quite fast. Although many algorithms do access the s…

---

## [Type stability when looping over fields in a heterogenous data struct](https://discourse.julialang.org/t/type-stability-when-looping-over-fields-in-a-heterogenous-data-struct/101643)

<div class="topic-metadata">

**Author:** [@james3](https://discourse.julialang.org/u/james3)\
**Replies:** 8\
**Last updated:** [July 17, 2023, 10:44pm UTC](https://discourse.julialang.org/t/type-stability-when-looping-over-fields-in-a-heterogenous-data-struct/101643 "2023-07-17T22:44:03Z")

</div>

I have a number of structs that contain arrays that vary in their dimension. I have a function that takes takes these structs, and loops over the fields, performing some operation. Suppose, for simplicity, that I was jus…

---

## [Convert Packed Image Format into Planar Format without Dependency](https://discourse.julialang.org/t/convert-packed-image-format-into-planar-format-without-dependency/100784)

<div class="topic-metadata">

**Author:** [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)\
**Replies:** 7\
**Last updated:** [July 3, 2023, 1:03pm UTC](https://discourse.julialang.org/t/convert-packed-image-format-into-planar-format-without-dependency/100784 "2023-07-03T13:03:01Z")

</div>

I am loading images using FileIO.jl. I want to convert the output into a Planar Format of the appropriate element type. I want to achieve this without any farther dependencies, so channelview() as in Most idomatic way …

---

## [WIOD database in Julia](https://discourse.julialang.org/t/wiod-database-in-julia/100759)

<div class="topic-metadata">

**Author:** [@Guido](https://discourse.julialang.org/u/Guido)\
**Replies:** 3\
**Last updated:** [June 25, 2023, 4:08pm UTC](https://discourse.julialang.org/t/wiod-database-in-julia/100759 "2023-06-25T16:08:35Z")

</div>

I’m working on World Input-Output Database (WIOD) from Groningen. Usually, I work this data using STATA. What I have so far is my usual do file template translated in Julia language, but I want to do it in Julia from sc…

---

## [Hard Disk storage solution for a (large) array of matrices](https://discourse.julialang.org/t/hard-disk-storage-solution-for-a-large-array-of-matrices/99734)

<div class="topic-metadata">

**Author:** [@Mouad](https://discourse.julialang.org/u/Mouad)\
**Replies:** 12\
**Last updated:** [June 1, 2023, 9:33pm UTC](https://discourse.julialang.org/t/hard-disk-storage-solution-for-a-large-array-of-matrices/99734 "2023-06-01T21:33:02Z")

</div>

I just finished an enormous scientific simulation (billions of regressions, trillions of allocations). The final output are a few arrays of matrices: 100000-element Vector{Matrix{Float64}}. I am looking for a solution t…

---

## [Storing collections of heterogeneous data](https://discourse.julialang.org/t/storing-collections-of-heterogeneous-data/99159)

<div class="topic-metadata">

**Author:** [@bvanderbeek](https://discourse.julialang.org/u/bvanderbeek)\
**Replies:** 7\
**Last updated:** [May 20, 2023, 9:55pm UTC](https://discourse.julialang.org/t/storing-collections-of-heterogeneous-data/99159 "2023-05-20T21:55:38Z")

</div>

I’m writing some Julia code in which I need to loop over a collection of observations. The observations are not all of the same type and each type of observation is defined in a specific structure. I need to then perform…

---

## [Implementing a Trie](https://discourse.julialang.org/t/implementing-a-trie/99022)

<div class="topic-metadata">

**Author:** [@spionkaese](https://discourse.julialang.org/u/spionkaese)\
**Replies:** 6\
**Last updated:** [May 19, 2023, 4:06pm UTC](https://discourse.julialang.org/t/implementing-a-trie/99022 "2023-05-19T16:06:10Z")

</div>

I am currently trying to implement a (bitwise?) Trie mapping Ints to some type V, and want to branch k bits at a time (resulting in 2^k children per node). For a first attempt I went with k = 1 and my nodes looked like …

---

## [How to create a list/vector/matrix of specified size, each value filled with -Inf or Inf?](https://discourse.julialang.org/t/how-to-create-a-list-vector-matrix-of-specified-size-each-value-filled-with-inf-or-inf/98040)

<div class="topic-metadata">

**Author:** [@meet.saiya](https://discourse.julialang.org/u/meet.saiya)\
**Replies:** 2\
**Last updated:** [April 28, 2023, 1:58pm UTC](https://discourse.julialang.org/t/how-to-create-a-list-vector-matrix-of-specified-size-each-value-filled-with-inf-or-inf/98040 "2023-04-28T13:58:01Z")

</div>

Hi all, Is there a way to create a vector or list or matrix of specified size, all of them initialized to either of the infinity values? There are functions for zeros, ones and so on. I was wondering if there is one for…

[Next page](https://discourse.julialang.org/tag/data-structures/213.md?match_all_tags=true&page=1&tags%5B%5D=data_structures)
