代码拉取完成,页面将自动刷新
同步操作将从 Ascend/mind-cluster 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/* Copyright(C) 2023. Huawei Technologies Co.,Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package common a series of common function
package common
import (
"strconv"
"ascend-common/common-utils/hwlog"
)
type int32Tool struct {
}
type int64Tool struct {
}
type stringTool struct {
}
// Int32Tool slice for int32 tool
var Int32Tool int32Tool
// Int64Tool slice for int64 tool
var Int64Tool int64Tool
// StringTool slice for string tool
var StringTool stringTool
// Contains slice for int32 contains
func (i int32Tool) Contains(sources []int32, target int32) bool {
for _, sourceNum := range sources {
if sourceNum == target {
return true
}
}
return false
}
// SameElement slice for int64 has same element with others slice
func (i int64Tool) SameElement(sources, targets []int64) bool {
for _, source := range sources {
for _, target := range targets {
if source == target {
return true
}
}
}
return false
}
// Remove slice for int64 remove target
func (i int64Tool) Remove(sources []int64, target int64) []int64 {
if len(sources) == 0 {
return sources
}
index := i.Index(sources, target)
if index == -1 {
return sources
}
return i.Remove(append(sources[:index], sources[index+1:]...), target)
}
// Index slice for int64 search the index with target
func (i int64Tool) Index(sources []int64, target int64) int {
for index, source := range sources {
if source == target {
return index
}
}
return -1
}
// ToHexString slice for int64 to Hex string
func (i int64Tool) ToHexString(sources []int64) string {
var target string
for i, source := range sources {
if i == 0 {
target = strconv.FormatInt(source, Hex)
continue
}
target = target + "," + strconv.FormatInt(source, Hex)
}
return target
}
// Abs return a absolute value between two int 64 value
func (i int64Tool) Abs(var1, var2 int64) int64 {
if var1 > var2 {
return var1 - var2
}
return var2 - var1
}
// Contains slice for int64 contains
func (i int64Tool) Contains(sources []int64, target int64) bool {
for _, sourceNum := range sources {
if sourceNum == target {
return true
}
}
return false
}
// Index slice for string search the index with target
func (s stringTool) Index(sources []string, target string) int {
for i, source := range sources {
if source == target {
return i
}
}
return -1
}
// SameElement string slice has same element with others slice
func (s stringTool) SameElement(sources, targets []string) bool {
for _, source := range sources {
for _, target := range targets {
if source == target {
return true
}
}
}
return false
}
// HexStringToInt hex string slice to int64 slice
func (s stringTool) HexStringToInt(sources []string) []int64 {
intSlice := make([]int64, 0, len(sources))
for _, source := range sources {
num, err := strconv.ParseInt(source, Hex, 0)
if err != nil {
hwlog.RunLog.Errorf("parse hex int failed and skip it, string: %s", source)
continue
}
intSlice = append(intSlice, num)
}
return intSlice
}
// Contains check whether slice contains target
func (s stringTool) Contains(sources []string, target string) bool {
for _, v := range sources {
if v == target {
return true
}
}
return false
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。