Questions tagged [insertion-order]

For questions relating to the maintenance of the insertion order of objects into a collection/container.

35 questions
146
votes
15 answers

A std::map that keep track of the order of insertion?

I currently have a std::map that stores an integer value to a unique string identifier, and I do look up with the string. It does mostly what I want, except that it does not keep track of the insertion order. So when I iterate the…
polyglot
  • 9,945
  • 10
  • 49
  • 63
22
votes
2 answers

Insertion-Order Dictionary (like Java's LinkedHashMap) in Swift?

Is there a standard swift class that is a Dictionary, but keeps keys in insertion-order like Java's LinkedHashMap? If not, how would one be implemented?
Heath Borders
  • 30,998
  • 16
  • 147
  • 256
17
votes
3 answers

List implementation that maintains ordering

Is there an existing List implementation in Java that maintains order based on provided Comparator? Something that can be used in the following way: Comparator cmp = new MyComparator(); List l = new OrderedList(cmp); l.add(someT); so…
Op De Cirkel
  • 28,647
  • 6
  • 40
  • 53
8
votes
2 answers

Order of insertion for worst case black height of a red black tree

Lets say we are dealing with the keys 1-15. To get the worst case performance of a regular BST, you would insert the keys in ascending or descending order as follows: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 Then the BST would essentially…
Jordan
  • 4,928
  • 4
  • 26
  • 39
7
votes
2 answers

Rank-Preserving Data Structure other than std:: vector?

I am faced with an application where I have to design a container that has random access (or at least better than O(n)) has inexpensive (O(1)) insert and removal, and stores the data according to the order (rank) specified at insertion. For example…
Code Doggo
  • 2,146
  • 6
  • 33
  • 58
4
votes
1 answer

Does a collection which is retrieved from map.values() method preserve insertion order?

I have an instance of LinkedHashMap. LinkedHashMap preserves the insertion order. I need to get the values of this map and I need them to be in the same order. So if I call values() method on this LinkedHashMap, the Collection that I retrieve from…
3
votes
2 answers

How preserve order of LinkedHashMap while serializing to GWT AutoBean?

I've tried using Map, HashMap and LinkedHashMap as a type for AutoBean factory and always after serializing it's changing initial elements order. I don't want to send additional ArrayList that will hold the order data. Is there a way to force…
denu
  • 2,170
  • 2
  • 23
  • 28
2
votes
1 answer

insertion sort does not order array correctly

Here is my insertion sort, exactly the way it is in the book "introduction to algorithms": def insertion_sort(): A = [5,2,4,6,1,3] for j in range(1, len(A)): print 'j:'+str(j) key = A[j] print 'key:'+str(key) …
Atma
  • 29,141
  • 56
  • 198
  • 299
2
votes
1 answer

persistent data structure (in Scala) that supports fast lookup AND insertion order?

When I work with maps, I tend to prefer ones whose elements can be iterated through in the same order they were inserted. It makes them feel more deterministic and easier to test. For this reason and others I've always been a sucker for…
James McCabe
  • 1,879
  • 2
  • 15
  • 22
2
votes
2 answers

Java ListSet somewhere?

Looking for a insertion order collection that also allows efficient querying and subset views of positions (like sublist). Seems the most straightforward option for this would be to take the linked list approach of List, embed the nodes as map…
i30817
  • 1,356
  • 2
  • 13
  • 26
1
vote
2 answers

How to insert only new and/or updated lines into another file

First days dealing with Perl and blocked already :) Here's the situation: a file is updated in folder A but also exists in folders B, C & D and, to make it easier, it can be different in all of them so I can't just do a diff. New lines that are…
1
vote
2 answers

Changing Object keys & values and preserving the initial order

Given the state object below { colour: ['red', 'blue', 'green'], size: ['small', 'medium', 'large'], position: ['bottom', 'top', 'left', 'right'], } I need to be able to change/update its attribute values attrValues as well as the attribute…
Ricardo Sanchez
  • 4,935
  • 11
  • 56
  • 86
1
vote
3 answers

Sorting Object of Object with sort and reduce function

I have an object like this //input let data={ "51": {"name": "text51"}, "54": {"name": "text54"}, "61": {"name": "text61"}, "64": {"name": "text64"}, "71": {"name": "text71"}, "74": {"name": "text74"}, "81": {"name":…
Niyaz
  • 797
  • 1
  • 8
  • 18
1
vote
2 answers

Insert a String To a Sorted String list without using native c++ functions

I have to insert a string inside an already sorted list of strings, what is the best way to achieve this to find the exact position to insert without having to sort all the list and not adding the string upfront. I just need to find the position to…
1
vote
0 answers

How can we maintain insertion order for set when using spring mvc and hibernate with annotation

My requirement is to convert an image to thumbnail, the first image selected by user should get converted to thumbnail, but as of now since i am using set it is not happening. How can i implement this with spring mvc and hibernate. I tried using…
1
2 3