If you slice implements sort.Sort, you can remove duplicates using Kevin 
Gillete's set package.

https://godoc.org/github.com/xtgo/set#Uniq

On Thursday, 15 December 2016 04:15:01 UTC+11, Michael Jones wrote:
>
> Do we know anything about the structure of the slice? 
>
>  
>
> It is inherent in the general notion that there must be a comparison of a 
> new item with existing ones to establish uniqueness. Even so, knowledge 
> about the structure of the input can make this comparison easier.
>
>  
>
> If the input is already ordered, then testing against the prior element is 
> a test against all elements.
>
>  
>
> If the input is integers in a small range then a bit mask presence test is 
> good.
>
>  
>
> If avoiding allocation is important one could sort the list O(n log n) and 
> then scan it O(n)
>
>  
>
> The hash (map/dictionary) approach is good, general, and slightly more 
> space efficient with a slice of struct{} since presence testing is all that 
> is necessary.
>
>  
>
> An O(n) scan to build a histogram would let you know about ranges and 
> potential sections for subsequent processing.
>
>  
>
> Many well-known approaches.
>
>  
>
> *From: *<golan...@googlegroups.com <javascript:>> on behalf of ali oygur <
> alio...@gmail.com <javascript:>>
> *Date: *Wednesday, December 14, 2016 at 3:41 AM
> *To: *golang-nuts <golan...@googlegroups.com <javascript:>>
> *Subject: *[go-nuts] Re: Idiomatic way to remove duplicates in a slice
>
>  
>
> there is good gist.
>
> https://gist.github.com/alioygur/16c66b4249cb42715091fe010eec7e33
>
> 12 Ağustos 2012 Pazar 06:33:54 UTC+4 tarihinde Sathish VJ yazdı:
>
> Is there an efficient, idiomatic way to remove duplicates in a slice?  
>
> If possible, I do want to retain the original order of items.  
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts...@googlegroups.com <javascript:>.
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to