Unordered Set gets messed up when created from a Vector

This indeed looks like a bug to me.
When creating an UnorderedSet from a Vector object, the order is not maintained.

var c = DOpus.NewVector(
	'1. Title',
	'2. Artists',
	'3. Album',
	'4. Album Artist',
	'5. Genre',
	'6. Year',
	'7. Track',
	'8. Disk',
	'9. Comment',
	'10. Publisher',
	'11. Copyright',
	'12. Rating');
DOpus.Output('===VECTOR===');
for (var i = 0; i < c.length; i++) {
	DOpus.Output(c(i));
}

var columns = DOpus.Create().UnorderedSet(c);
DOpus.Output('===SET FROM VECTOR===');
for (var i = 0; i < columns.length; i++) {
	DOpus.Output(columns(i));
}

This happens in DO v13.10.2

EDIT: It seems this also happens when adding items one by one. So it looks like the UnorderedSet is actually giving a random order.

var c = DOpus.Create().Vector(
	'1. Title',
	'2. Artists',
	'3. Album',
	'4. Album Artist',
	'5. Genre',
	'6. Year',
	'7. Track',
	'8. Disk',
	'9. Comment',
	'10. Publisher',
	'11. Copyright',
	'12. Rating');
var columns = DOpus.Create().UnorderedSet();
DOpus.Output('===VECTOR===');
for (var i = 0; i < c.length; i++) {
	DOpus.Output(c(i));
	columns.insert(c(i));
}

DOpus.Output('===SET FROM VECTOR===');
for (var i = 0; i < columns.length; i++) {
	DOpus.Output(columns(i));
}

Not a bug; from UnorderedSet [Directory Opus Manual] :

the contents are not kept sorted (in fact, the order of set members is unspecified)

In other words, UnorderedSet is for when you don't care what order things are in. (It's usually more efficient than keeping them sorted.)

You might be confusing it with OrderedMap [Directory Opus Manual].

1 Like