arrays

package
v0.0.0-...-512269d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2023 License: MIT Imports: 8 Imported by: 0

README

concurrent_map

  • sync.Map
    • 特点:
      1. 适用于大量读、少量写的场景(变化较少的缓存)
      2. 读取、写入和覆盖map不相交的键集合
    • 缺点
      • 不适用与大量读写的场景
  • Map 加锁
    • 优点
      • 结构简单,适用于所有读写场景
    • 缺点
      • 采用全局锁,性能较差
  • concurrent_map
    • 特点
      • 采用分段锁的概念
      • 内部采用读写锁(sync.RWMutex)
      • 内部结构
      var SHARD_COUNT =32
      type ConcurrentMapShared struct {
       items map[string]interface{}
       sync.RWMutex
      
      }  
      

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SHARD_COUNT = 32

Functions

func Compact

func Compact(arr []interface{}) []interface{}

func Contains

func Contains(search interface{}, target interface{}) bool

Contains 判断某个元素是否在slice, array, map中

func ContainsIgnoreCase

func ContainsIgnoreCase(search string, target []string) bool

ContainsIgnoreCase check if a string (search) is present in a slice of strings (target) regardless of the case. words := []string{"Apple", "Banana", "Cherry", "Date", "Fig", "Grape"}

fmt.Println(ContainsIgnoreCase("apple", words)) // true
fmt.Println(ContainsIgnoreCase("BANANA", words)) // true
fmt.Println(ContainsIgnoreCase("Cherry", words)) // true
fmt.Println(ContainsIgnoreCase("date", words)) // true
fmt.Println(ContainsIgnoreCase("fig", words)) // true
fmt.Println(ContainsIgnoreCase("grape", words)) // true
fmt.Println(ContainsIgnoreCase("kiwi", words)) // false

func CopyShallowMap

func CopyShallowMap(m map[string]string) map[string]string

CopyShallowMap makes a shallow copy of a map

func Difference

func Difference(a, b []string) (diff []string)

Difference returns the difference between two string slices

func Equal

func Equal(a, b interface{}) bool

Equal reports whether a and b are deeply equal. Map keys are always compared with ==, not deeply. (This matters for keys containing pointers or interfaces)

func Flatten

func Flatten(arr []interface{}) []interface{}

Flatten 返回一个新的一维平面数组 Returns a new array that is one-dimensional flat. Example:

var arr1 = []interface{}{1, 2, 3, 4}       // [1, 2, 3, 4]
var arr2 = []interface{}{5, 6, 7, arr1}    // [5, 6, 7, [1, 2, 3, 4]]
result := arrays.Flatten(arr2)          // [5, 6, 7, 1, 2, 3, 4]

func InInt64Array

func InInt64Array(target int64, int64Array []int64) bool

*

  • @name: InInt64Array
  • @descripttion: 是否在Int64列表中
  • @param {string} target
  • @param {[]string} strArray
  • @return {bool}

func InIntArray

func InIntArray(target int, intArray []int) bool

*

  • @name: InIntArray
  • @descripttion: 是否在Int列表中
  • @param {string} target
  • @param {[]string} strArray
  • @return {bool}

func InStringArray

func InStringArray(target string, strArray []string) bool

*

  • @name: InStringArray
  • @descripttion: 是否在字符串列表中
  • @param {string} target
  • @param {[]string} strArray
  • @return {bool}

func JoinInts

func JoinInts(list []int64) string

JoinInts format int64 to slice like: n1, n2, n3

func Map

func Map(arr []interface{}, f MapFunc) []interface{}

func RemoveDuplicate

func RemoveDuplicate(slice []string) []string

RemoveDuplicate 删除[]string 中的重复元素

func ReverseStringSlice

func ReverseStringSlice(slice []string) []string

ReverseStringSlice 反转字符串切片 [site user info 0 ] -> [0 info user site]

func SpliteInts

func SpliteInts(s string) ([]int64, error)

SpliteInts split string into int64 slice.

func StringArrayEqual

func StringArrayEqual(arr1, arr2 []int) bool

*

  • @name: IntArrayEqual
  • @descripttion: 判断IntArray是否相等
  • @param {[]int} arr1
  • @param {[]int} arr2
  • @return {bool}

func ToSlice

func ToSlice(arr interface{}) []interface{}

ToSlice 转换为数组

func UniqueString

func UniqueString(stringSlice []string) []string

UniqueString returns a unique string from a slice

Types

type ConcurrentMap

type ConcurrentMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

A "thread" safe map of type string:Anything To avoid lock bottlenecks this map is dived to severel (SHARD_COUNT) map shards

type ConcurrentMapShared

type ConcurrentMapShared[K comparable, V any] struct {
	sync.RWMutex // Read Write mutex, guards access to internal map
	// contains filtered or unexported fields
}

A "thread“ safe string to anything map

type MapFunc

type MapFunc func(v interface{}) interface{}

type Stringer

type Stringer interface {
	fmt.Stringer
	comparable
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL