Skip to content

Commit 191be7d

Browse files
Alexey Stukalovalyst
authored andcommitted
nonunique() helper function
1 parent 887763a commit 191be7d

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/additional_functions/helper.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,18 @@ function commutation_matrix_pre_square_add_mt!(B, A) # comuptes B + KₙA # 0 al
246246

247247
return B
248248
end
249+
250+
# returns the vector of non-unique values in the order of appearance
251+
# each non-unique values is reported once
252+
function nonunique(values::AbstractVector)
253+
value_counts = Dict{eltype(values), Int}()
254+
res = similar(values, 0)
255+
for v in values
256+
n = get!(value_counts, v, 0)
257+
if n == 1 # second encounter
258+
push!(res, v)
259+
end
260+
value_counts[v] = n + 1
261+
end
262+
return res
263+
end

0 commit comments

Comments
 (0)