forked from Layr-Labs/eigenda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into size-aware-cache
Signed-off-by: Cody Littley <[email protected]>
- Loading branch information
Showing
73 changed files
with
2,479 additions
and
621 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package common | ||
|
||
type ReadOnlyMap[K comparable, V any] struct { | ||
data map[K]V | ||
} | ||
|
||
func NewReadOnlyMap[K comparable, V any](data map[K]V) *ReadOnlyMap[K, V] { | ||
return &ReadOnlyMap[K, V]{data: data} | ||
} | ||
|
||
func (m *ReadOnlyMap[K, V]) Get(key K) (V, bool) { | ||
value, ok := m.data[key] | ||
return value, ok | ||
} | ||
|
||
func (m *ReadOnlyMap[K, V]) Keys() []K { | ||
keys := make([]K, 0, len(m.data)) | ||
for key := range m.data { | ||
keys = append(keys, key) | ||
} | ||
return keys | ||
} | ||
|
||
func (m *ReadOnlyMap[K, V]) Len() int { | ||
return len(m.data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package common_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/Layr-Labs/eigenda/common" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestReadOnlyMap(t *testing.T) { | ||
data := map[uint8]string{ | ||
1: "one", | ||
2: "two", | ||
3: "three", | ||
} | ||
m := common.NewReadOnlyMap(data) | ||
res, ok := m.Get(1) | ||
require.True(t, ok) | ||
require.Equal(t, "one", res) | ||
res, ok = m.Get(2) | ||
require.True(t, ok) | ||
require.Equal(t, "two", res) | ||
res, ok = m.Get(3) | ||
require.True(t, ok) | ||
require.Equal(t, "three", res) | ||
res, ok = m.Get(4) | ||
require.False(t, ok) | ||
require.Equal(t, "", res) | ||
require.Equal(t, 3, m.Len()) | ||
require.ElementsMatch(t, []uint8{1, 2, 3}, m.Keys()) | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.