Implement Cmp() functions for ID-like structs #333
No reviewers
TrueCloudLab/storage-services-developers
TrueCloudLab/storage-services-committers
Labels
No labels
P0
P1
P2
P3
good first issue
pool
Infrastructure
blocked
bug
config
discussion
documentation
duplicate
enhancement
go
help wanted
internal
invalid
kludge
observability
perfomance
question
refactoring
wontfix
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: TrueCloudLab/frostfs-sdk-go#333
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "achuprov/frostfs-sdk-go:feat/add_Cmp"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Close #294
e35d88d0f1
to0f97a1e917
0f97a1e917
toaf34872561
Note:
Base58
lexicographic order does not match theASCII
lexicographic order.@ -116,0 +117,4 @@
// Cmp returns an integer comparing two base58 encoded container ID lexicographically.
// The result will be 0 if a == b, -1 if a < b, and +1 if a > b.
func (id ID) Cmp(id2 ID) int {
func Cmp(id1, id2 ID) int
?SortFunc(ids, cid.Cmp)
will look better thanSortFunc(ids, (cid.ID).Cmp)
a
->id1
,b
->id2
Compare
similar to how it's done in the standard library?I think we should use NeoGo code style.
Disagree but approve
@ -116,0 +118,4 @@
// Cmp returns an integer comparing two base58 encoded container ID lexicographically.
// The result will be 0 if a == b, -1 if a < b, and +1 if a > b.
func (id ID) Cmp(id2 ID) int {
return bytes.Compare([]byte(id.EncodeToString()), []byte(id2.EncodeToString()))
Is there any reason to use
bytes.Compare
instead ofstrings.Compare
?@ -109,0 +119,4 @@
slices.SortFunc(arr, cid.ID.Cmp)
for i := 1; i < len(arr); i++ {
if bytes.Compare([]byte(arr[i-1].EncodeToString()), []byte(arr[i].EncodeToString())) > 0 {
Can you use
testify
library here?@ -109,0 +120,4 @@
for i := 1; i < len(arr); i++ {
if bytes.Compare([]byte(arr[i-1].EncodeToString()), []byte(arr[i].EncodeToString())) > 0 {
t.Fatalf("arrays are not sorted correctly")
"arrayS". How many?
Fatalf
->Fatal
af34872561
toaecf878669
aecf878669
toa2c2db17c2
@ -109,0 +119,4 @@
slices.SortFunc(arr, cid.ID.Cmp)
for i := 1; i < len(arr); i++ {
require.NotEqual(t, strings.Compare(arr[i-1].EncodeToString(), arr[i].EncodeToString()), 1, "array are not sorted correctly")
array IS
a2c2db17c2
to5d49b313be
@ -107,2 +109,4 @@
})
}
func TestID__Cmp(t *testing.T) {
TestID__Cmp
->TestID_Cmp
?5d49b313be
to614b0cc480
New commits pushed, approval review dismissed automatically according to repository settings
New commits pushed, approval review dismissed automatically according to repository settings