Fisrt functional version

This commit is contained in:
Eric Coissac
2024-11-14 19:10:23 +01:00
parent 9471fedfa1
commit 03f4e88a17
26 changed files with 908 additions and 307 deletions

View File

@ -5,7 +5,7 @@ import "sync"
// InnerString is a struct that holds a map of strings and a read-write lock for concurrent access.
// The index map is used to store key-value pairs of strings.
type InnerString struct {
index map[string]string
index map[string]*string
lock sync.RWMutex
}
@ -13,7 +13,7 @@ type InnerString struct {
// The lock is set to false.
func NewInnerString() *InnerString {
return &InnerString{
index: make(map[string]string),
index: make(map[string]*string),
}
}
@ -26,13 +26,13 @@ func NewInnerString() *InnerString {
//
// Returns:
// - The string value associated with the key.
func (i *InnerString) Innerize(value string) string {
func (i *InnerString) Innerize(value string) *string {
i.lock.Lock()
defer i.lock.Unlock()
s, ok := i.index[value]
if !ok {
i.index[value] = value
s = value
s = &value
i.index[value] = s
}
return s
@ -42,7 +42,7 @@ func (i *InnerString) Slice() []string {
rep := make([]string, len(i.index))
j := 0
for _, v := range i.index {
rep[j] = v
rep[j] = *v
j++
}
return rep