Logo

Programming-Idioms

History of Idiom 119 > diff from v9 to v10

Edit summary for version 10 by :
[D]

Version 9

2016-01-24, 03:06:02

Version 10

2016-01-29, 01:41:12

Idiom #119 Deduplicate list

Remove duplicates from list x.
Explain if original order is preserved.

Idiom #119 Deduplicate list

Remove duplicates from list x.
Explain if original order is preserved.

Imports
Imports
import std.container;
import std.array;
Code
bool[typeof(x[0])] aa;

foreach (elem ; x)
    aa[elem] = true;

x = aa.keys;
Code
x = redBlackTree(x)[].array;
Comments bubble
Using an associative array. It uses "typeof(x[0])" to be generic, in a real code we would know the type of x and wouldn't need such trick.
Comments bubble
Converts to a set then back to an array
Doc URL
http://dlang.org/phobos/std_container_rbtree.html#.redBlackTree