Questions tagged [ordered-set]

16 questions
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
7
votes
1 answer

Time Complexity of OrderedSet() in python

I was going through this answer on Stack Overflow. I came to know about existence of OrderedSet in Python. I would like to know how it is implemented internally. Is it similar to hash table implementation of sets? Also, what is the time complexity…
likecs
  • 353
  • 2
  • 13
3
votes
1 answer

Does Erlang Mnesia select on an ordered_set give a list in Erlang Term order?

In the documentation it isn't clear to me whether I need to iterate through in order with either next or perhaps foldl (it is mentioned that foldr goes in the opposite order to ordered_set so presuambly foldl goes in the same order) or if I can use…
3
votes
1 answer

Provide OrderedSet[int] like types using stub file without modifying ordered-set library

I've contributed type hints for ordered-set library. The problem is that despite I have the following lines in ordered_set.pyi file: from typing import MutableSet, TypeVar, Sequence T = TypeVar('T') class OrderedSet(MutableSet[T], Sequence[T]): …
rominf
  • 2,719
  • 3
  • 21
  • 39
2
votes
1 answer

Set vs OrderedSet

Can you please give me an example when to use OrderedSet instead of Set? I've run a couple of tests and even tho the immutable-js documentation says Iteration order of a Set is undefined, however is stable it seems element order within Set is…
sKopheK
  • 149
  • 13
2
votes
1 answer

Output the contents of an ETS Table Erlang

I am new to the world of Erlang so I am trying to experiment with it. I have an ETS table that is called numbers. ets:new(numbers,[ordered_set,named_table]) It has the format [{Name,Number},{Name,Number}] etc. I am wondering is there a way to…
Fendec
  • 367
  • 1
  • 5
  • 23
1
vote
5 answers

Set that uniquely contains a key but ordered on different field

I'm looking for a Java collection, possibly in standard library, which is able to collect the following structure: class Item { String key; double score; } And with the following properties: Only one Item with the same key is allowed (like…
Jack
  • 1,488
  • 11
  • 21
1
vote
1 answer

Gnuplot - How to join smoothly ordered points?

I've a set of data in three columns: 1st column: order criterion between 0 and 1 2nd: x vals 3rd: y vals As a data file example: 0.027 -29.3 -29.6 0.071 -26.0 -31.0 0.202 -14.0 -32.8 0.304 -3.4 -29.3 0.329 -0.5 …
Ben
  • 11
  • 2
1
vote
1 answer

best data structure to record a Pareto front

May I ask if someone has already seen or faced the following problem? I need to handle a list of cost/profit values c1/p1, c2/p2, c3/p3,... that satisfies: c1≤c2≤c3≤c4... p1≤p2≤p3≤p4... This is an example: 2/3, 4/5, 9/15, 12/19 If one tries to…
0
votes
3 answers

Finding an Intersection between two lists or dataframes while enforcing an ordering condition

I have two lists (columns from two separate pandas dataframes) and want to find the intersection of both lists while preserving the order, or ordering based on a condition. Consider the following example: x = ['0 MO', '1 YR', '10 YR', '15 YR', '2…
Paddy
  • 91
  • 7
0
votes
0 answers

Redis Ordered Set of objects with O(1) retrieval by a GUID key and sorted by another 64-bit signed integer key in descending order

I have a map of sets of unique objects, unique based on it's GUID as key, and sorted by timestamp, a 64-bit signed integer in descending order. The sets are keyed by a GUID and every individual object in the each set should be able to be retrieved…
Kok How Teh
  • 3,298
  • 6
  • 47
  • 85
0
votes
1 answer

Does OrderedSet() still have a search parameter of O(1)?

I have heard that when you perform an in operator on a list it has to search through O(n) objects while if you do it on a set it has to search through O(1) objects. To see what I mean go here. Does this still apply to OrderedSet?
Fateh
  • 302
  • 2
  • 12
0
votes
1 answer

Function that returns the union(in alphabetic order) of two sets in Lisp

The procedure below takes two lists and returns their union as an ordered list. (defun stable-union (lst1 lst2) (cond ((null lst1) lst2) ((null lst2) lst1) ((and (null lst1) (null lst2)) nil) (t (let ((el1 (car…
0
votes
1 answer

Data structure for permutations in Java

I need to store a permutation of n integers and be able to compute both the permutation of a value and the inverse operation in efficient time. I.e, I need to store a reordering of values [0...n-1] in such a way I can ask for position(i) and…
1
2