-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve delete performance for clickhouse
- Loading branch information
Showing
6 changed files
with
265 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package common | ||
|
||
type Set[T comparable] struct { | ||
elements map[T]struct{} | ||
} | ||
|
||
// NewSet creates a new set | ||
func NewSet[T comparable]() *Set[T] { | ||
return &Set[T]{ | ||
elements: make(map[T]struct{}), | ||
} | ||
} | ||
|
||
// Add inserts an element into the set | ||
func (s *Set[T]) Add(value T) { | ||
s.elements[value] = struct{}{} | ||
} | ||
|
||
// Remove deletes an element from the set | ||
func (s *Set[T]) Remove(value T) { | ||
delete(s.elements, value) | ||
} | ||
|
||
// Contains checks if an element is in the set | ||
func (s *Set[T]) Contains(value T) bool { | ||
_, found := s.elements[value] | ||
return found | ||
} | ||
|
||
// Size returns the number of elements in the set | ||
func (s *Set[T]) Size() int { | ||
return len(s.elements) | ||
} | ||
|
||
// List returns all elements in the set as a slice | ||
func (s *Set[T]) List() []T { | ||
keys := make([]T, 0, len(s.elements)) | ||
for key := range s.elements { | ||
keys = append(keys, key) | ||
} | ||
return keys | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.