Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change OrderedMap.Get() to return Value instead of Storable #318

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions cmd/stress/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,10 @@ func checkMapDataLoss(m *atree.OrderedMap, elements map[atree.Value]atree.Value)

// Check every element
for k, v := range elements {
storable, err := m.Get(compare, hashInputProvider, k)
convertedValue, err := m.Get(compare, hashInputProvider, k)
if err != nil {
return fmt.Errorf("failed to get element with key %s: %w", k, err)
}
convertedValue, err := storable.StoredValue(m.Storage)
if err != nil {
return fmt.Errorf("failed to convert storable to value with key %s: %w", k, err)
}
err = valueEqual(v, convertedValue)
if err != nil {
return fmt.Errorf("failed to compare %s and %s: %w", v, convertedValue, err)
Expand Down
20 changes: 18 additions & 2 deletions map.go
Original file line number Diff line number Diff line change
Expand Up @@ -3606,7 +3606,7 @@ func NewMapWithRootID(storage SlabStorage, rootID StorageID, digestBuilder Diges
}

func (m *OrderedMap) Has(comparator ValueComparator, hip HashInputProvider, key Value) (bool, error) {
_, err := m.Get(comparator, hip, key)
_, err := m.get(comparator, hip, key)
if err != nil {
var knf *KeyNotFoundError
if errors.As(err, &knf) {
Expand All @@ -3618,7 +3618,23 @@ func (m *OrderedMap) Has(comparator ValueComparator, hip HashInputProvider, key
return true, nil
}

func (m *OrderedMap) Get(comparator ValueComparator, hip HashInputProvider, key Value) (Storable, error) {
func (m *OrderedMap) Get(comparator ValueComparator, hip HashInputProvider, key Value) (Value, error) {

storable, err := m.get(comparator, hip, key)
if err != nil {
// Don't need to wrap error as external error because err is already categorized by MapSlab.Get().
return nil, err
}

v, err := storable.StoredValue(m.Storage)
if err != nil {
// Wrap err as external error (if needed) because err is returned by Storable interface.
return nil, wrapErrorfAsExternalErrorIfNeeded(err, "failed to get storable's stored value")
}
return v, nil
}

func (m *OrderedMap) get(comparator ValueComparator, hip HashInputProvider, key Value) (Storable, error) {

keyDigest, err := m.digesterBuilder.Digest(hip, key)
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ func verifyMap(

// Verify map elements
for k, v := range keyValues {
s, err := m.Get(compare, hashInputProvider, k)
require.NoError(t, err)

e, err := s.StoredValue(m.Storage)
e, err := m.Get(compare, hashInputProvider, k)
require.NoError(t, err)

valueEqual(t, typeInfoComparator, v, e)
Expand Down