Set-Append function for nsTArray
Categories
(Core :: XPCOM, enhancement)
Tracking
()
People
(Reporter: vhilla, Unassigned)
Details
During review of Bug 1830781, we wondered whether a function for set-append would make sense in nsTArray.
Some of these usages of if (!array.Contains(item) { array.AppendElement(item) } could be replaced with something like array.SetAppend(item).
Comment 1•2 years ago
|
||
Is nsTArray the right data structure in the first place? Would a hashmap work better?
| Reporter | ||
Comment 2•2 years ago
|
||
I'm sorry, I should clarify that set refers to ordered set. Also see the note there:
Almost all cases on the web platform require an ordered set, instead of an unordered one, since interoperability requires that any developer-exposed enumeration of the set’s contents be consistent between browsers.
Comment 3•2 years ago
|
||
As described in the link, by "ordered set" what they really mean is a set where the iteration order is the order the elements were first inserted into the set. They should really call it an "insertion ordered set" or something, as normally I think somebody would assume the ordering would be based on the value of the elements.
Comment 4•2 years ago
|
||
You could use a set and an array. Only insert iterms in the array if they aren't in the set.
Description
•