github.com/primecitizens/pcz/std@v0.2.1/core/bytealg/count.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 && !(amd64 || arm || arm64 || ppc64le || ppc64 || riscv64 || s390x)
     9  
    10  package bytealg
    11  
    12  func CountSlice(b []byte, c byte) int {
    13  	n := 0
    14  	for _, x := range b {
    15  		if x == c {
    16  			n++
    17  		}
    18  	}
    19  	return n
    20  }
    21  
    22  func Count(s string, c byte) int {
    23  	n := 0
    24  	for i := 0; i < len(s); i++ {
    25  		if s[i] == c {
    26  			n++
    27  		}
    28  	}
    29  	return n
    30  }