insertion-order


Java ListSet somewhere?

烂漫一生 提交于 2019-12-24 00:30:05
问题 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 values and expose part or all of the list interface on the class. Would someone bitch to Oracle about this? Having NavigableMap/Set added for sorted maps and sets and not having the far more common insertion order equivalent... edit: please don't

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

倾然丶 夕夏残阳落幕 提交于 2019-12-18 12:54:08
问题 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? 回答1: Didn't know of one and it was an interesting problem to solve (already put it in my standard library of stuff) Mostly it's just a matter of maintaining a dictionary and an array of the keys side-by-side. But standard operations like for (key, value) in od and for key in od.keys will iterate in insertion order rather than a semi random

List implementation that maintains ordering

一世执手 提交于 2019-12-04 16:20:19
问题 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<T> cmp = new MyComparator<T>(); List<T> l = new OrderedList<T>(cmp); l.add(someT); so that someT gets inserted such that the order in the list is maintained according to cmp (On @andersoj suggestion I am completing my question with one more request) Also I want to be able to traverse the list in sorted order without removing the

List implementation that maintains ordering

爷,独闯天下 提交于 2019-12-03 10:24:13
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<T> cmp = new MyComparator<T>(); List<T> l = new OrderedList<T>(cmp); l.add(someT); so that someT gets inserted such that the order in the list is maintained according to cmp (On @andersoj suggestion I am completing my question with one more request) Also I want to be able to traverse the list in sorted order without removing the elements, i.e: T min = Const.SMALLEST_T; for (T e: l) { assertTrue(cmp.compare(min, e) >= 0); min = e; }

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

有些话、适合烂在心里 提交于 2019-11-26 07:43:21
I currently have a std::map<std::string,int> that stores an integer value to an unique string identifier, and I do look up with the string. It does mostly what I want, except for that it does not keep track of the insertion order. So when I iterate the the map to print out the values, they are sorted according to the string; but I want them to be sorted according to the order of (first) insertion. I thought about using a vector<pair<string,int>> instead, but I need to look up the string and increment the integer values about 10,000,000 times, so I don't know whether a std::vector will be

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

大兔子大兔子 提交于 2019-11-26 01:58:34
问题 I currently have a std::map<std::string,int> that stores an integer value to an unique string identifier, and I do look up with the string. It does mostly what I want, except for that it does not keep track of the insertion order. So when I iterate the the map to print out the values, they are sorted according to the string; but I want them to be sorted according to the order of (first) insertion. I thought about using a vector<pair<string,int>> instead, but I need to look up the string and

工具导航Map