From 8d02bbcd024cf77a14b6feb31ca7a4aadec330c7 Mon Sep 17 00:00:00 2001 From: Faye Amacker <33205765+fxamacker@users.noreply.github.com> Date: Tue, 3 Oct 2023 15:49:57 -0500 Subject: [PATCH] Rename variables for clarity --- map.go | 48 +++++++++++++++---------------- map_test.go | 80 +++++++++++++++++++++++++-------------------------- utils_test.go | 6 ++-- 3 files changed, 67 insertions(+), 67 deletions(-) diff --git a/map.go b/map.go index b67674cb..349faf28 100644 --- a/map.go +++ b/map.go @@ -135,7 +135,7 @@ type element interface { hip HashInputProvider, key Value, value Value, - ) (newElem element, keyStorable MapKey, existingValue MapValue, err error) + ) (newElem element, keyStorable MapKey, existingMapValueStorable MapValue, err error) // Remove returns matched key, value, and updated element. // Updated element may be nil, modified, or a different type of element. @@ -654,7 +654,7 @@ func (e *singleElement) Set( // Key matches, overwrite existing value if equal { - existingValue := e.value + existingMapValueStorable := e.value valueStorable, err := value.Storable(storage, address, maxInlineMapValueSize(uint64(e.key.ByteSize()))) if err != nil { @@ -664,7 +664,7 @@ func (e *singleElement) Set( e.value = valueStorable e.size = singleElementPrefixSize + e.key.ByteSize() + e.value.ByteSize() - return e, e.key, existingValue, nil + return e, e.key, existingMapValueStorable, nil } // Hash collision detected @@ -822,7 +822,7 @@ func (e *inlineCollisionGroup) Set( } hkey, _ := digester.Digest(level) - keyStorable, existingValue, err := e.elements.Set(storage, address, b, digester, level, hkey, comparator, hip, key, value) + keyStorable, existingMapValueStorable, err := e.elements.Set(storage, address, b, digester, level, hkey, comparator, hip, key, value) if err != nil { // Don't need to wrap error as external error because err is already categorized by elements.Set(). return nil, nil, nil, err @@ -863,11 +863,11 @@ func (e *inlineCollisionGroup) Set( return &externalCollisionGroup{ slabID: id, size: externalCollisionGroupPrefixSize + SlabIDStorable(id).ByteSize(), - }, keyStorable, existingValue, nil + }, keyStorable, existingMapValueStorable, nil } } - return e, keyStorable, existingValue, nil + return e, keyStorable, existingMapValueStorable, nil } // Remove returns key, value, and updated element if key is found. @@ -1021,12 +1021,12 @@ func (e *externalCollisionGroup) Set( } hkey, _ := digester.Digest(level) - keyStorable, existingValue, err := slab.Set(storage, b, digester, level, hkey, comparator, hip, key, value) + keyStorable, existingMapValueStorable, err := slab.Set(storage, b, digester, level, hkey, comparator, hip, key, value) if err != nil { // Don't need to wrap error as external error because err is already categorized by MapSlab.Set(). return nil, nil, nil, err } - return e, keyStorable, existingValue, nil + return e, keyStorable, existingMapValueStorable, nil } // Remove returns key, value, and updated element if key is found. @@ -1498,7 +1498,7 @@ func (e *hkeyElements) Set( } } - elem, keyStorable, existingValue, err := elem.Set(storage, address, b, digester, level, hkey, comparator, hip, key, value) + elem, keyStorable, existingMapValueStorable, err := elem.Set(storage, address, b, digester, level, hkey, comparator, hip, key, value) if err != nil { // Don't need to wrap error as external error because err is already categorized by element.Set(). return nil, nil, err @@ -1515,7 +1515,7 @@ func (e *hkeyElements) Set( } e.size = size - return keyStorable, existingValue, nil + return keyStorable, existingMapValueStorable, nil } // No matching hkey @@ -2017,8 +2017,8 @@ func (e *singleElements) Set( } if equal { - existingKey := elem.key - existingValue := elem.value + existingKeyStorable := elem.key + existingValueStorable := elem.value vs, err := value.Storable(storage, address, maxInlineMapValueSize(uint64(elem.key.ByteSize()))) if err != nil { @@ -2038,7 +2038,7 @@ func (e *singleElements) Set( } e.size = size - return existingKey, existingValue, nil + return existingKeyStorable, existingValueStorable, nil } } @@ -3177,7 +3177,7 @@ func (m *MapDataSlab) Set( value Value, ) (MapKey, MapValue, error) { - keyStorable, existingValue, err := m.elements.Set(storage, m.SlabID().address, b, digester, level, hkey, comparator, hip, key, value) + keyStorable, existingMapValueStorable, err := m.elements.Set(storage, m.SlabID().address, b, digester, level, hkey, comparator, hip, key, value) if err != nil { // Don't need to wrap error as external error because err is already categorized by elements.Set(). return nil, nil, err @@ -3198,7 +3198,7 @@ func (m *MapDataSlab) Set( } } - return keyStorable, existingValue, nil + return keyStorable, existingMapValueStorable, nil } func (m *MapDataSlab) Remove(storage SlabStorage, digester Digester, level uint, hkey Digest, comparator ValueComparator, key Value) (MapKey, MapValue, error) { @@ -3888,7 +3888,7 @@ func (m *MapMetaDataSlab) Set( return nil, nil, err } - keyStorable, existingValue, err := child.Set(storage, b, digester, level, hkey, comparator, hip, key, value) + keyStorable, existingMapValueStorable, err := child.Set(storage, b, digester, level, hkey, comparator, hip, key, value) if err != nil { // Don't need to wrap error as external error because err is already categorized by MapSlab.Set(). return nil, nil, err @@ -3907,7 +3907,7 @@ func (m *MapMetaDataSlab) Set( // Don't need to wrap error as external error because err is already categorized by MapMetaDataSlab.SplitChildSlab(). return nil, nil, err } - return keyStorable, existingValue, nil + return keyStorable, existingMapValueStorable, nil } if underflowSize, underflow := child.IsUnderflow(); underflow { @@ -3916,7 +3916,7 @@ func (m *MapMetaDataSlab) Set( // Don't need to wrap error as external error because err is already categorized by MapMetaDataSlab.MergeOrRebalanceChildSlab(). return nil, nil, err } - return keyStorable, existingValue, nil + return keyStorable, existingMapValueStorable, nil } err = storage.Store(m.header.slabID, m) @@ -3924,7 +3924,7 @@ func (m *MapMetaDataSlab) Set( // Wrap err as external error (if needed) because err is returned by SlabStorage interface. return nil, nil, wrapErrorfAsExternalErrorIfNeeded(err, fmt.Sprintf("failed to store slab %s", m.header.slabID)) } - return keyStorable, existingValue, nil + return keyStorable, existingMapValueStorable, nil } func (m *MapMetaDataSlab) Remove(storage SlabStorage, digester Digester, level uint, hkey Digest, comparator ValueComparator, key Value) (MapKey, MapValue, error) { @@ -4902,13 +4902,13 @@ func (m *OrderedMap) set(comparator ValueComparator, hip HashInputProvider, key return nil, wrapErrorfAsExternalErrorIfNeeded(err, fmt.Sprintf("failed to get map key digest at level %d", level)) } - keyStorable, existingValue, err := m.root.Set(m.Storage, m.digesterBuilder, keyDigest, level, hkey, comparator, hip, key, value) + keyStorable, existingMapValueStorable, err := m.root.Set(m.Storage, m.digesterBuilder, keyDigest, level, hkey, comparator, hip, key, value) if err != nil { // Don't need to wrap error as external error because err is already categorized by MapSlab.Set(). return nil, err } - if existingValue == nil { + if existingMapValueStorable == nil { m.root.ExtraData().incrementCount() } @@ -4957,7 +4957,7 @@ func (m *OrderedMap) set(comparator ValueComparator, hip HashInputProvider, key maxInlineSize := maxInlineMapValueSize(uint64(keyStorable.ByteSize())) m.setCallbackWithChild(comparator, hip, key, value, maxInlineSize) - return existingValue, nil + return existingMapValueStorable, nil } func (m *OrderedMap) Remove(comparator ValueComparator, hip HashInputProvider, key Value) (Storable, Storable, error) { @@ -5724,12 +5724,12 @@ func NewMapFromBatchData( prevElem := elements.elems[lastElementIndex] prevElemSize := prevElem.Size() - elem, _, existingValue, err := prevElem.Set(storage, address, digesterBuilder, digester, 0, hkey, comparator, hip, key, value) + elem, _, existingMapValueStorable, err := prevElem.Set(storage, address, digesterBuilder, digester, 0, hkey, comparator, hip, key, value) if err != nil { // Don't need to wrap error as external error because err is already categorized by element.Set(). return nil, err } - if existingValue != nil { + if existingMapValueStorable != nil { return nil, NewDuplicateKeyError(key) } diff --git a/map_test.go b/map_test.go index 6cdb0144..9cdf0b11 100644 --- a/map_test.go +++ b/map_test.go @@ -7882,15 +7882,15 @@ func TestEmptyMap(t *testing.T) { }) t.Run("remove", func(t *testing.T) { - existingKey, existingValue, err := m.Remove(compare, hashInputProvider, Uint64Value(0)) + existingMapKeyStorable, existingMapValueStorable, err := m.Remove(compare, hashInputProvider, Uint64Value(0)) require.Equal(t, 1, errorCategorizationCount(err)) var userError *UserError var keyNotFoundError *KeyNotFoundError require.ErrorAs(t, err, &userError) require.ErrorAs(t, err, &keyNotFoundError) require.ErrorAs(t, userError, &keyNotFoundError) - require.Nil(t, existingKey) - require.Nil(t, existingValue) + require.Nil(t, existingMapKeyStorable) + require.Nil(t, existingMapValueStorable) }) t.Run("iterate", func(t *testing.T) { @@ -10882,10 +10882,10 @@ func TestChildMapInlinabilityInParentMap(t *testing.T) { } for _, k := range keys { - existingKey, existingValue, err := childMap.Remove(compare, hashInputProvider, k) + existingMapKeyStorable, existingMapValueStorable, err := childMap.Remove(compare, hashInputProvider, k) require.NoError(t, err) - require.Equal(t, k, existingKey) - require.NotNil(t, existingValue) + require.Equal(t, k, existingMapKeyStorable) + require.NotNil(t, existingMapValueStorable) delete(expectedChildMapValues, k) @@ -11041,10 +11041,10 @@ func TestChildMapInlinabilityInParentMap(t *testing.T) { break } - existingKey, existingValue, err := childMap.Remove(compare, hashInputProvider, aKey) + existingMapKeyStorable, existingMapValueStorable, err := childMap.Remove(compare, hashInputProvider, aKey) require.NoError(t, err) - require.Equal(t, aKey, existingKey) - require.NotNil(t, existingValue) + require.Equal(t, aKey, existingMapKeyStorable) + require.NotNil(t, existingMapValueStorable) delete(expectedChildMapValues, aKey) @@ -11084,10 +11084,10 @@ func TestChildMapInlinabilityInParentMap(t *testing.T) { } for _, k := range keys { - existingKey, existingValue, err := childMap.Remove(compare, hashInputProvider, k) + existingMapKeyStorable, existingMapValueStorable, err := childMap.Remove(compare, hashInputProvider, k) require.NoError(t, err) - require.Equal(t, k, existingKey) - require.NotNil(t, existingValue) + require.Equal(t, k, existingMapKeyStorable) + require.NotNil(t, existingMapValueStorable) delete(expectedChildMapValues, k) @@ -11231,10 +11231,10 @@ func TestChildMapInlinabilityInParentMap(t *testing.T) { break } - existingKey, existingValue, err := childMap.Remove(compare, hashInputProvider, aKey) + existingMapKeyStorable, existingMapValueStorable, err := childMap.Remove(compare, hashInputProvider, aKey) require.NoError(t, err) - require.Equal(t, aKey, existingKey) - require.NotNil(t, existingValue) + require.Equal(t, aKey, existingMapKeyStorable) + require.NotNil(t, existingMapValueStorable) delete(expectedChildMapValues, aKey) @@ -11268,10 +11268,10 @@ func TestChildMapInlinabilityInParentMap(t *testing.T) { } for _, k := range keys { - existingKey, existingValue, err := childMap.Remove(compare, hashInputProvider, k) + existingMapKeyStorable, existingMapValueStorable, err := childMap.Remove(compare, hashInputProvider, k) require.NoError(t, err) - require.Equal(t, k, existingKey) - require.NotNil(t, existingValue) + require.Equal(t, k, existingMapKeyStorable) + require.NotNil(t, existingMapValueStorable) delete(expectedChildMapValues, k) @@ -11515,10 +11515,10 @@ func TestNestedThreeLevelChildMapInlinabilityInParentMap(t *testing.T) { } for _, k := range gchildKeys { - existingKey, existingValue, err := gchildMap.Remove(compare, hashInputProvider, k) + existingMapKey, existingMapValueStorable, err := gchildMap.Remove(compare, hashInputProvider, k) require.NoError(t, err) - require.Equal(t, k, existingKey) - require.NotNil(t, existingValue) + require.Equal(t, k, existingMapKey) + require.NotNil(t, existingMapValueStorable) delete(expectedGChildMapValues, k) @@ -11782,10 +11782,10 @@ func TestNestedThreeLevelChildMapInlinabilityInParentMap(t *testing.T) { // Remove all elements (large element first) to trigger grand child map being inlined again. for _, k := range keys { - existingKey, existingValue, err := gchildMap.Remove(compare, hashInputProvider, k) + existingMapKeyStorable, existingMapValueStorable, err := gchildMap.Remove(compare, hashInputProvider, k) require.NoError(t, err) - require.Equal(t, k, existingKey) - require.NotNil(t, existingValue) + require.Equal(t, k, existingMapKeyStorable) + require.NotNil(t, existingMapValueStorable) delete(expectedGChildMapValues, k) @@ -12101,10 +12101,10 @@ func TestNestedThreeLevelChildMapInlinabilityInParentMap(t *testing.T) { } // Remove one element - existingKey, existingValue, err := childMap.Remove(compare, hashInputProvider, aKey) + existingMapKeyStorable, existingMapValueStorable, err := childMap.Remove(compare, hashInputProvider, aKey) require.NoError(t, err) - require.Equal(t, aKey, existingKey) - require.NotNil(t, existingValue) + require.Equal(t, aKey, existingMapKeyStorable) + require.NotNil(t, existingMapValueStorable) delete(expectedChildMapValues, aKey) @@ -12171,10 +12171,10 @@ func TestNestedThreeLevelChildMapInlinabilityInParentMap(t *testing.T) { // Remove all elements, except grand child map for _, k := range keys { - existingKey, existingValue, err := childMap.Remove(compare, hashInputProvider, k) + existingMapKeyStorable, existingMapValueStorable, err := childMap.Remove(compare, hashInputProvider, k) require.NoError(t, err) - require.Equal(t, k, existingKey) - require.NotNil(t, existingValue) + require.Equal(t, k, existingMapKeyStorable) + require.NotNil(t, existingMapValueStorable) delete(expectedChildMapValues, k) @@ -12417,10 +12417,10 @@ func TestNestedThreeLevelChildMapInlinabilityInParentMap(t *testing.T) { } // Remove one element from grand child map - existingKey, existingValue, err := gchildMap.Remove(compare, hashInputProvider, aKey) + existingMapKeyStorable, existingMapValueStorable, err := gchildMap.Remove(compare, hashInputProvider, aKey) require.NoError(t, err) - require.Equal(t, aKey, existingKey) - require.NotNil(t, existingValue) + require.Equal(t, aKey, existingMapKeyStorable) + require.NotNil(t, existingMapValueStorable) delete(expectedGChildMapValues, aKey) @@ -12473,13 +12473,13 @@ func TestNestedThreeLevelChildMapInlinabilityInParentMap(t *testing.T) { // Remove grand children for _, k := range keys { - existingKey, existingValue, err := childMap.Remove(compare, hashInputProvider, k) + existingMapKeyStorable, existingMapValueStorable, err := childMap.Remove(compare, hashInputProvider, k) require.NoError(t, err) - require.Equal(t, k, existingKey) - require.NotNil(t, existingValue) + require.Equal(t, k, existingMapKeyStorable) + require.NotNil(t, existingMapValueStorable) // Grand child map is returned as SlabIDStorable, even if it was stored inlined in the parent. - id, ok := existingValue.(SlabIDStorable) + id, ok := existingMapValueStorable.(SlabIDStorable) require.True(t, ok) v, err := id.StoredValue(storage) @@ -12659,10 +12659,10 @@ func TestChildMapWhenParentMapIsModified(t *testing.T) { for _, k := range keysForNonChildMaps { - existingKey, existingValue, err := parentMap.Remove(compare, hashInputProvider, k) + existingMapKeyStorable, existingMapValueStorable, err := parentMap.Remove(compare, hashInputProvider, k) require.NoError(t, err) - require.NotNil(t, existingKey) - require.NotNil(t, existingValue) + require.NotNil(t, existingMapKeyStorable) + require.NotNil(t, existingMapValueStorable) delete(expectedKeyValues, k) diff --git a/utils_test.go b/utils_test.go index 6bcd6608..3388d4bb 100644 --- a/utils_test.go +++ b/utils_test.go @@ -147,12 +147,12 @@ func (i testCompositeTypeInfo) Equal(other TypeInfo) bool { } func typeInfoComparator(a, b TypeInfo) bool { - switch x := a.(type) { + switch a := a.(type) { case testTypeInfo: - return x.Equal(b) + return a.Equal(b) case testCompositeTypeInfo: - return x.Equal(b) + return a.Equal(b) default: return false