Skip to content

Commit

Permalink
Remove duplicates in final list
Browse files Browse the repository at this point in the history
This PR addresses joshmedeski#156 and removes duplicates based on the Path entries.

Performance time is linear wrt number of entries.
  • Loading branch information
szinn committed Jan 27, 2025
1 parent 213388d commit 92aa5cf
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lister/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ func (l *RealLister) List(opts ListOptions) (model.SeshSessions, error) {
}
}

directoryHash := make(map[string]int)
destIndex := 0
for _, index := range fullOrderedIndex {
directory := fullDirectory[index]
if _, exists := directoryHash[directory.Path]; !exists {
fullOrderedIndex[destIndex] = index
directoryHash[directory.Path] = 1
destIndex = destIndex + 1
}
}
fullOrderedIndex = fullOrderedIndex[:destIndex]

return model.SeshSessions{
OrderedIndex: fullOrderedIndex,
Directory: fullDirectory,
Expand Down

0 comments on commit 92aa5cf

Please sign in to comment.