Skip to content

Commit

Permalink
docs: change comment in table
Browse files Browse the repository at this point in the history
  • Loading branch information
siyul-park committed Nov 26, 2023
1 parent 985ee25 commit 6bc257e
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions pkg/symbol/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,30 @@ import (
)

type (
// TableOptions is a options for Table.
// TableOptions holds options for configuring a Table.
TableOptions struct {
LoadHooks []LoadHook
UnloadHooks []UnloadHook
LoadHooks []LoadHook // LoadHooks define functions to be executed on symbol loading.
UnloadHooks []UnloadHook // UnloadHooks define functions to be executed on symbol unloading.
}

// Table is the storage that manages Symbol.
// Table manages the storage and operations for Symbols.
Table struct {
symbols map[ulid.ULID]*Symbol
unlinks map[ulid.ULID]map[string][]scheme.PortLocation
symbols map[ulid.ULID]*Symbol
unlinks map[ulid.ULID]map[string][]scheme.PortLocation
linked map[ulid.ULID]map[string][]scheme.PortLocation
index map[string]map[string]ulid.ULID
loadHooks []LoadHook
unloadHooks []UnloadHook
mu sync.RWMutex
loadHooks []LoadHook
unloadHooks []UnloadHook
mu sync.RWMutex
}
)

// NewTable returns a new SymbolTable
// NewTable creates a new SymbolTable with the specified options.
func NewTable(opts ...TableOptions) *Table {
var loadHooks []LoadHook
var unloadHooks []UnloadHook

// Collect load and unload hooks from the provided options.
for _, opt := range opts {
loadHooks = append(loadHooks, opt.LoadHooks...)
unloadHooks = append(unloadHooks, opt.UnloadHooks...)

Check warning on line 38 in pkg/symbol/table.go

View check run for this annotation

Codecov / codecov/patch

pkg/symbol/table.go#L37-L38

Added lines #L37 - L38 were not covered by tests
Expand All @@ -47,8 +48,9 @@ func NewTable(opts ...TableOptions) *Table {
}
}

// Insert inserts a node.Node.
// Insert adds a Symbol to the table.
func (t *Table) Insert(sym *Symbol) error {
// Lock the table to ensure atomicity.
t.mu.Lock()
defer t.mu.Unlock()

Expand All @@ -60,6 +62,7 @@ func (t *Table) Insert(sym *Symbol) error {
return err
}

Check warning on line 63 in pkg/symbol/table.go

View check run for this annotation

Codecov / codecov/patch

pkg/symbol/table.go#L62-L63

Added lines #L62 - L63 were not covered by tests
}

if sym.Node != prev.Node {
if err := prev.Close(); err != nil {
return err
Expand All @@ -68,6 +71,7 @@ func (t *Table) Insert(sym *Symbol) error {
}

t.symbols[sym.ID()] = sym

if prev != nil && prev.Name() != "" {
if namespace, ok := t.index[prev.Namespace()]; ok {
delete(namespace, prev.Name())
Expand All @@ -76,6 +80,7 @@ func (t *Table) Insert(sym *Symbol) error {
}

Check warning on line 80 in pkg/symbol/table.go

View check run for this annotation

Codecov / codecov/patch

pkg/symbol/table.go#L76-L80

Added lines #L76 - L80 were not covered by tests
}
}

t.index[sym.Namespace()] = lo.Assign(t.index[sym.Namespace()], map[string]ulid.ULID{sym.Name(): sym.ID()})

var deletions map[string][]scheme.PortLocation
Expand Down Expand Up @@ -237,7 +242,7 @@ func (t *Table) Insert(sym *Symbol) error {
return nil
}

// Free removes a Symbol.
// Free removes a Symbol from the table.
func (t *Table) Free(id ulid.ULID) (bool, error) {
t.mu.Lock()
defer t.mu.Unlock()
Expand Down Expand Up @@ -280,7 +285,7 @@ func (t *Table) Free(id ulid.ULID) (bool, error) {
return false, nil
}

// LookupByID returns a Symbol.
// LookupByID retrieves a Symbol by its ID.
func (t *Table) LookupByID(id ulid.ULID) (*Symbol, bool) {
t.mu.RLock()
defer t.mu.RUnlock()
Expand All @@ -289,7 +294,7 @@ func (t *Table) LookupByID(id ulid.ULID) (*Symbol, bool) {
return sym, ok
}

// LookupByID returns a Symbol.
// LookupByID retrieves a Symbol by its namespace and name.
func (t *Table) LookupByName(namespace, name string) (*Symbol, bool) {
t.mu.RLock()
defer t.mu.RUnlock()

Check warning on line 300 in pkg/symbol/table.go

View check run for this annotation

Codecov / codecov/patch

pkg/symbol/table.go#L298-L300

Added lines #L298 - L300 were not covered by tests
Expand All @@ -303,7 +308,7 @@ func (t *Table) LookupByName(namespace, name string) (*Symbol, bool) {
return nil, false

Check warning on line 308 in pkg/symbol/table.go

View check run for this annotation

Codecov / codecov/patch

pkg/symbol/table.go#L308

Added line #L308 was not covered by tests
}

// Close closes the SymbolTable.
// Close closes the SymbolTable, closing all associated symbols.
func (t *Table) Close() error {
t.mu.Lock()
defer t.mu.Unlock()
Expand Down

0 comments on commit 6bc257e

Please sign in to comment.