github.com/primecitizens/pcz/std@v0.2.1/core/cmp/bs.generic.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  //
     4  // Copyright 2018 The Go Authors. All rights reserved.
     5  // Use of this source code is governed by a BSD-style
     6  // license that can be found in the LICENSE file.
     7  
     8  //go:build pcz && !(386 || amd64 || s390x || arm || arm64 || ppc64 || ppc64le || mips || mipsle || wasm || mips64 || mips64le || riscv64)
     9  
    10  package cmp
    11  
    12  func Bytes(a, b []byte) int {
    13  	l := min(len(a), len(b))
    14  	if l == 0 || &a[0] == &b[0] {
    15  		goto samebytes
    16  	}
    17  	for i := 0; i < l; i++ {
    18  		c1, c2 := a[i], b[i]
    19  		if c1 < c2 {
    20  			return -1
    21  		}
    22  		if c1 > c2 {
    23  			return +1
    24  		}
    25  	}
    26  samebytes:
    27  	if len(a) < len(b) {
    28  		return -1
    29  	}
    30  	if len(a) > len(b) {
    31  		return +1
    32  	}
    33  	return 0
    34  }
    35  
    36  func String(a, b string) int {
    37  	l := min(len(a), len(b))
    38  	for i := 0; i < l; i++ {
    39  		c1, c2 := a[i], b[i]
    40  		if c1 < c2 {
    41  			return -1
    42  		}
    43  		if c1 > c2 {
    44  			return +1
    45  		}
    46  	}
    47  	if len(a) < len(b) {
    48  		return -1
    49  	}
    50  	if len(a) > len(b) {
    51  		return +1
    52  	}
    53  	return 0
    54  }