Restructured code into 'cmd' module with CLI and 'greg' module with regex library; export necessary struct fields and methods

This commit is contained in:
2025-01-30 08:56:03 -05:00
parent 54df6f1815
commit 1a2f1b7ca9
17 changed files with 37 additions and 35 deletions

39
cmd/unique_array.go Normal file
View File

@@ -0,0 +1,39 @@
package main
// Unique array data structure
type uniq_arr[T comparable] struct {
backingMap map[T]struct{} // Map is used to check if element exists - Empty structs occupy zero memory
}
func new_uniq_arr[T comparable]() uniq_arr[T] {
return uniq_arr[T]{
make(map[T]struct{}),
}
}
func (s *uniq_arr[T]) add(vals ...T) {
for _, item := range vals {
if !s.contains(item) {
s.backingMap[item] = struct{}{}
}
}
return
}
func (s uniq_arr[T]) contains(val T) bool {
_, ok := s.backingMap[val]
return ok
}
func (s *uniq_arr[T]) delete(val T) {
delete(s.backingMap, val)
}
func (s uniq_arr[T]) values() []T {
toRet := make([]T, len(s.backingMap))
i := 0
for k := range s.backingMap {
toRet[i] = k
i++
}
return toRet
}