Questions tagged [ordered-map]

A list-map hybrid. As with a regular map, it allows fast random access by key; and as with a regular list, it maintains the keys in a consistent order, which can be manipulated and queried using standard list operations.

37 questions
48
votes
6 answers

Scala Map implementation keeping entries in insertion order?

In Java, I use LinkedHashMap for this purpose. The documentation of Java's LinkedHashMap is very clear that it has "predictable iteration order" and I need the same in Scala. Scala has ListMap and LinkedHashMap, but the documentation on what they do…
ebruchez
  • 7,760
  • 6
  • 29
  • 41
10
votes
1 answer

How to get the maximum and minimum value of an ordered set / ordered map?

Rust's ordered set is a BTreeSet: use std::collections::BTreeSet; // Type inference lets us omit an explicit type signature (which // would be `BTreeSet<&str>` in this example). let mut books = BTreeSet::new(); // Add some books. books.insert("A…
Jeremy Cochoy
  • 2,480
  • 2
  • 24
  • 39
9
votes
2 answers

How to define an ordered Map/Set with a runtime-defined comparator?

This is similar to How do I use a custom comparator function with BTreeSet? however in my case I won't know the sorting criteria until runtime. The possible criteria are extensive and can't be hard-coded (think something like sort by distance to…
kmdreko
  • 42,554
  • 6
  • 57
  • 106
6
votes
2 answers

How to use unordered_map in cython?

I want a step by step guide, how to use unordered_map in cython. I've included file unordered_map.pxd into Cython/Includes/libcpp from https://gist.github.com/ikuyamada/3265267 and use 3 other files: main.py: import…
Apogentus
  • 6,371
  • 6
  • 32
  • 33
4
votes
2 answers

Parsing YAML, get line numbers even in ordered maps

I need to get the line numbers of certain keys of a YAML file. Please note, this answer does not solve the issue: I do use ruamel.yaml, and the answers do not work with ordered maps. #!/usr/bin/env python3 # -*- coding: utf-8 -*- from ruamel import…
zezollo
  • 4,606
  • 5
  • 28
  • 59
4
votes
5 answers

Ordered Map Implementation in JavaScript

My Task In my JavaScript code i'm often using objects to "map" keys to values so i can later access them directly through a certain value. For example: var helloMap = {}; helloMap.de = "Hallo"; helloMap["en"] = "Hello"; helloMap.es = "Hola"; So i…
Chris
  • 7,675
  • 8
  • 51
  • 101
3
votes
1 answer

Why there is no ordered hashmap in Redis?

Redis Data types includes sorted set and other necessary data-structures for key-value storage. But I wonder why it doesn't have any sorted map like Java's TreeMap or C++'s std::map. I think the underlying data-structure would be mostly similar of…
Kaidul
  • 15,409
  • 15
  • 81
  • 150
3
votes
1 answer

Which one is better when select the last entry of an ordered map in c++

auto& myKey = myMap.rbegin()->first; auto& myKey = std::prev(myMap.end())->first; myMap is a constant ordered map. Both of the approaches are with constant complexity. rbegin()uses reverse iterator, while std::prevworks on bidirectional iterator.…
Emerson Xu
  • 428
  • 6
  • 13
2
votes
3 answers

How to check if a "KEY" exist in a map for a given "VALUE" in C++

Recently I had been learning maps in C++ and I came across various problems where I need to check if a "KEY" exists for a given value. In JAVA we can do so by following code snippet - hash_map.containsValue(VALUE); // Returns true if there is a key…
2
votes
0 answers

New prosemirror.model lib (1.18.1) causes error in console: Schema is not a constructor

I'm rather new to React and now trying to fix an error that occurs at runtime due to a new version of prosemirror.model in our artifactory. The new version is 1.18.1, the old version that works was 1.16.1. Loading the page gives the following error…
Bartjo77
  • 21
  • 2
2
votes
2 answers

Missing property name after reference operator

I have a map, that is originally c++ code, file read, and parsed into a map. The original code was an enum, and didn't have values for all items. $fileContent: enum{ Error_A = 110, Error_B, Error_C, …
Michele
  • 3,617
  • 12
  • 47
  • 81
2
votes
2 answers

Why do we don't have hash and pred functors for a map?

In case of unordered_map we define the hash and pred functors whenever we are using user-defined keys. The template syntax for a map is as follows: template < class Key, // map::key_type class T, …
Navjot Singh
  • 678
  • 7
  • 18
2
votes
2 answers

Why does Symfony provide an OrderedHashMap

Symfony provides an OrderedHashMap. Its documentation states Unlike associative arrays, the map keeps track of the order in which keys were added and removed. This order is reflected during iteration. I'm confused by this statement, because I…
fishbone
  • 3,140
  • 2
  • 37
  • 50
2
votes
1 answer

Utility of an ordered map using binary search tree

I am currently learning different data structures and I'm facing a little problem. What's the use of an ordered map implemented using a binary search tree? I mean, when is it good to do it so? A practical example would be great!
2
votes
1 answer

scala map += operator with five pairs

I am having an issue with appending pairs to an existing Map. Once I reach the fifth pair of the Map, the Map reorders itself. The order is correct with 4 pairs, but as soon as the 5th is added it shifts itself. See example below (assuming I built…
tigga4392
  • 111
  • 1
  • 5
1
2 3