mirror of
https://github.com/tursom/GoCollections.git
synced 2025-04-27 05:50:27 +08:00
add lang.Number atomic.Float32/64
This commit is contained in:
parent
a839508b27
commit
fed6847099
@ -37,5 +37,5 @@ func (i Complex128) ToString() String {
|
||||
}
|
||||
|
||||
func (i Complex128) HashCode() int32 {
|
||||
return Float64(real(complex64(i))).HashCode() ^ Float64(imag(complex64(i))).HashCode()
|
||||
return HashFloat64(real(i)) ^ HashFloat64(imag(i))
|
||||
}
|
||||
|
@ -37,5 +37,5 @@ func (i Complex64) ToString() String {
|
||||
}
|
||||
|
||||
func (i Complex64) HashCode() int32 {
|
||||
return Float32(real(complex64(i))).HashCode() ^ Float32(imag(complex64(i))).HashCode()
|
||||
return Float32(real(i)).HashCode() ^ Float32(imag(i)).HashCode()
|
||||
}
|
||||
|
@ -12,7 +12,45 @@ import (
|
||||
|
||||
type Float32 float32
|
||||
|
||||
func (i Float32) AsFloat32() float32 {
|
||||
func CastFloat32(v any) (float32, bool) {
|
||||
switch i := v.(type) {
|
||||
case int:
|
||||
return float32(i), true
|
||||
case int8:
|
||||
return float32(i), true
|
||||
case int16:
|
||||
return float32(i), true
|
||||
case int32:
|
||||
return float32(i), true
|
||||
case int64:
|
||||
return float32(i), true
|
||||
case uint:
|
||||
return float32(i), true
|
||||
case uint8:
|
||||
return float32(i), true
|
||||
case uint16:
|
||||
return float32(i), true
|
||||
case uint32:
|
||||
return float32(i), true
|
||||
case uint64:
|
||||
return float32(i), true
|
||||
case float32:
|
||||
return i, true
|
||||
case float64:
|
||||
return float32(i), true
|
||||
case Number:
|
||||
return float32(i.ToFloat64().V()), true
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
func EqualsFloat32(i1 Number, i2 any) bool {
|
||||
i2, ok := CastFloat32(i2)
|
||||
return ok && i2 == i1.ToFloat64().V()
|
||||
}
|
||||
|
||||
func (i Float32) V() float32 {
|
||||
return float32(i)
|
||||
}
|
||||
|
||||
@ -25,11 +63,7 @@ func (i Float32) AsObject() Object {
|
||||
}
|
||||
|
||||
func (i Float32) Equals(e Object) bool {
|
||||
i2, ok := e.(Float32)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
return i == i2
|
||||
return EqualsFloat32(i, e)
|
||||
}
|
||||
|
||||
func (i Float32) ToString() String {
|
||||
@ -37,7 +71,7 @@ func (i Float32) ToString() String {
|
||||
}
|
||||
|
||||
func (i Float32) HashCode() int32 {
|
||||
return Hash32(&i)
|
||||
return HashFloat32(float32(i))
|
||||
}
|
||||
|
||||
func (i Float32) Compare(t Float32) int {
|
||||
@ -50,3 +84,19 @@ func (i Float32) Compare(t Float32) int {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
func (i Float32) ToInt64() Int64 {
|
||||
return Int64(i)
|
||||
}
|
||||
|
||||
func (i Float32) ToUInt64() UInt64 {
|
||||
return UInt64(i)
|
||||
}
|
||||
|
||||
func (i Float32) ToFloat64() Float64 {
|
||||
return Float64(i)
|
||||
}
|
||||
|
||||
func HashFloat32(f float32) int32 {
|
||||
return Hash32(&f)
|
||||
}
|
||||
|
@ -12,7 +12,45 @@ import (
|
||||
|
||||
type Float64 float64
|
||||
|
||||
func (i Float64) AsFloat64() float64 {
|
||||
func CastFloat64(v any) (float64, bool) {
|
||||
switch i := v.(type) {
|
||||
case int:
|
||||
return float64(i), true
|
||||
case int8:
|
||||
return float64(i), true
|
||||
case int16:
|
||||
return float64(i), true
|
||||
case int32:
|
||||
return float64(i), true
|
||||
case int64:
|
||||
return float64(i), true
|
||||
case uint:
|
||||
return float64(i), true
|
||||
case uint8:
|
||||
return float64(i), true
|
||||
case uint16:
|
||||
return float64(i), true
|
||||
case uint32:
|
||||
return float64(i), true
|
||||
case uint64:
|
||||
return float64(i), true
|
||||
case float32:
|
||||
return float64(i), true
|
||||
case float64:
|
||||
return i, true
|
||||
case Number:
|
||||
return i.ToFloat64().V(), true
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
func EqualsFloat64(i1 Number, i2 any) bool {
|
||||
i2, ok := CastFloat64(i2)
|
||||
return ok && i2 == i1.ToFloat64().V()
|
||||
}
|
||||
|
||||
func (i Float64) V() float64 {
|
||||
return float64(i)
|
||||
}
|
||||
|
||||
@ -25,11 +63,11 @@ func (i Float64) AsObject() Object {
|
||||
}
|
||||
|
||||
func (i Float64) Equals(e Object) bool {
|
||||
i2, ok := e.(Float64)
|
||||
i2, ok := CastFloat64(e)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
return i == i2
|
||||
return i.V() == i2
|
||||
}
|
||||
|
||||
func (i Float64) ToString() String {
|
||||
@ -37,7 +75,7 @@ func (i Float64) ToString() String {
|
||||
}
|
||||
|
||||
func (i Float64) HashCode() int32 {
|
||||
return Hash64(&i)
|
||||
return HashFloat64(float64(i))
|
||||
}
|
||||
|
||||
func (i Float64) Compare(t Float64) int {
|
||||
@ -50,3 +88,7 @@ func (i Float64) Compare(t Float64) int {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
func HashFloat64(f float64) int32 {
|
||||
return Hash64(&f)
|
||||
}
|
||||
|
@ -30,12 +30,12 @@ func HashAddr[V any](v *V) int32 {
|
||||
}
|
||||
|
||||
func Hash32[T any](p *T) int32 {
|
||||
return *(*int32)(unsafe.Pointer(p))
|
||||
return HashInt32(*(*int32)(unsafe.Pointer(p)))
|
||||
}
|
||||
|
||||
func Hash64[T any](p *T) int32 {
|
||||
i := *(*int64)(unsafe.Pointer(p))
|
||||
return int32(i) ^ int32(i>>32)
|
||||
return HashInt64(i)
|
||||
}
|
||||
|
||||
func HashString(str string) int32 {
|
||||
|
57
lang/Int.go
57
lang/Int.go
@ -10,25 +10,42 @@ import "strconv"
|
||||
|
||||
type Int int
|
||||
|
||||
type AsInt interface {
|
||||
Object
|
||||
AsInt() Int
|
||||
}
|
||||
|
||||
func CastInt(v any) (int, bool) {
|
||||
switch i := v.(type) {
|
||||
case int:
|
||||
return i, true
|
||||
case AsInt:
|
||||
return i.AsInt().V(), true
|
||||
case int8:
|
||||
return int(i), true
|
||||
case int16:
|
||||
return int(i), true
|
||||
case int32:
|
||||
return int(i), true
|
||||
case int64:
|
||||
return int(i), true
|
||||
case uint:
|
||||
return int(i), true
|
||||
case uint8:
|
||||
return int(i), true
|
||||
case uint16:
|
||||
return int(i), true
|
||||
case uint32:
|
||||
return int(i), true
|
||||
case uint64:
|
||||
return int(i), true
|
||||
case float32:
|
||||
return int(i), true
|
||||
case float64:
|
||||
return int(i), true
|
||||
case Number:
|
||||
return int(i.ToInt64().V()), true
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
func EqualsInt(i1 AsInt, i2 any) bool {
|
||||
func EqualsInt(i1 Number, i2 any) bool {
|
||||
i2, ok := CastInt(i2)
|
||||
return ok && i2 == i1.AsInt().V()
|
||||
return ok && i2 == i1.ToInt64().V()
|
||||
}
|
||||
|
||||
func (i Int) V() int {
|
||||
@ -39,10 +56,6 @@ func (i *Int) P() *int {
|
||||
return (*int)(i)
|
||||
}
|
||||
|
||||
func (i Int) AsInt() Int {
|
||||
return i
|
||||
}
|
||||
|
||||
func (i Int) String() string {
|
||||
return strconv.FormatInt(int64(i), 10)
|
||||
}
|
||||
@ -60,7 +73,7 @@ func (i Int) ToString() String {
|
||||
}
|
||||
|
||||
func (i Int) HashCode() int32 {
|
||||
return int32(i)
|
||||
return HashInt(int(i))
|
||||
}
|
||||
|
||||
func (i Int) Compare(t Int) int {
|
||||
@ -73,3 +86,19 @@ func (i Int) Compare(t Int) int {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
func (i Int) ToInt64() Int64 {
|
||||
return Int64(i)
|
||||
}
|
||||
|
||||
func (i Int) ToUInt64() UInt64 {
|
||||
return UInt64(i)
|
||||
}
|
||||
|
||||
func (i Int) ToFloat64() Float64 {
|
||||
return Float64(i)
|
||||
}
|
||||
|
||||
func HashInt(i int) int32 {
|
||||
return HashInt64(int64(i))
|
||||
}
|
||||
|
@ -10,25 +10,42 @@ import "strconv"
|
||||
|
||||
type Int16 int16
|
||||
|
||||
type AsInt16 interface {
|
||||
Object
|
||||
AsInt16() Int16
|
||||
}
|
||||
|
||||
func CastInt16(v any) (int16, bool) {
|
||||
switch i := v.(type) {
|
||||
case int:
|
||||
return int16(i), true
|
||||
case int8:
|
||||
return int16(i), true
|
||||
case int16:
|
||||
return i, true
|
||||
case AsInt16:
|
||||
return i.AsInt16().V(), true
|
||||
case int32:
|
||||
return int16(i), true
|
||||
case int64:
|
||||
return int16(i), true
|
||||
case uint:
|
||||
return int16(i), true
|
||||
case uint8:
|
||||
return int16(i), true
|
||||
case uint16:
|
||||
return int16(i), true
|
||||
case uint32:
|
||||
return int16(i), true
|
||||
case uint64:
|
||||
return int16(i), true
|
||||
case float32:
|
||||
return int16(i), true
|
||||
case float64:
|
||||
return int16(i), true
|
||||
case Number:
|
||||
return int16(i.ToInt64().V()), true
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
func EqualsInt16(i1 AsInt16, i2 any) bool {
|
||||
func EqualsInt16(i1 Number, i2 any) bool {
|
||||
i2, ok := CastInt16(i2)
|
||||
return ok && i2 == i1.AsInt16().V()
|
||||
return ok && i2 == i1.ToInt64().V()
|
||||
}
|
||||
|
||||
func (i Int16) V() int16 {
|
||||
@ -39,10 +56,6 @@ func (i *Int16) P() *int16 {
|
||||
return (*int16)(i)
|
||||
}
|
||||
|
||||
func (i Int16) AsInt16() Int16 {
|
||||
return i
|
||||
}
|
||||
|
||||
func (i Int16) String() string {
|
||||
return strconv.FormatInt(int64(i), 10)
|
||||
}
|
||||
@ -60,7 +73,7 @@ func (i Int16) ToString() String {
|
||||
}
|
||||
|
||||
func (i Int16) HashCode() int32 {
|
||||
return int32(i)
|
||||
return HashInt16(int16(i))
|
||||
}
|
||||
|
||||
func (i Int16) Compare(t Int16) int {
|
||||
@ -73,3 +86,19 @@ func (i Int16) Compare(t Int16) int {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
func (i Int16) ToInt64() Int64 {
|
||||
return Int64(i)
|
||||
}
|
||||
|
||||
func (i Int16) ToUInt64() UInt64 {
|
||||
return UInt64(i)
|
||||
}
|
||||
|
||||
func (i Int16) ToFloat64() Float64 {
|
||||
return Float64(i)
|
||||
}
|
||||
|
||||
func HashInt16(i int16) int32 {
|
||||
return HashInt32(int32(i))
|
||||
}
|
||||
|
@ -12,25 +12,42 @@ type Int32 int32
|
||||
|
||||
type Rune = Int32
|
||||
|
||||
type AsInt32 interface {
|
||||
Object
|
||||
AsInt32() Int32
|
||||
}
|
||||
|
||||
func CastInt32(v any) (int32, bool) {
|
||||
switch i := v.(type) {
|
||||
case int:
|
||||
return int32(i), true
|
||||
case int8:
|
||||
return int32(i), true
|
||||
case int16:
|
||||
return int32(i), true
|
||||
case int32:
|
||||
return i, true
|
||||
case AsInt32:
|
||||
return i.AsInt32().V(), true
|
||||
case int64:
|
||||
return int32(i), true
|
||||
case uint:
|
||||
return int32(i), true
|
||||
case uint8:
|
||||
return int32(i), true
|
||||
case uint16:
|
||||
return int32(i), true
|
||||
case uint32:
|
||||
return int32(i), true
|
||||
case uint64:
|
||||
return int32(i), true
|
||||
case float32:
|
||||
return int32(i), true
|
||||
case float64:
|
||||
return int32(i), true
|
||||
case Number:
|
||||
return int32(i.ToInt64().V()), true
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
func EqualsInt32(i1 AsInt32, i2 any) bool {
|
||||
func EqualsInt32(i1 Number, i2 any) bool {
|
||||
i2, ok := CastInt32(i2)
|
||||
return ok && i2 == i1.AsInt32().V()
|
||||
return ok && i2 == i1.ToInt64().V()
|
||||
}
|
||||
|
||||
func (i Int32) V() int32 {
|
||||
@ -41,10 +58,6 @@ func (i *Int32) P() *int32 {
|
||||
return (*int32)(i)
|
||||
}
|
||||
|
||||
func (i Int32) AsInt32() Int32 {
|
||||
return i
|
||||
}
|
||||
|
||||
func (i Int32) String() string {
|
||||
return strconv.FormatInt(int64(i), 10)
|
||||
}
|
||||
@ -62,7 +75,7 @@ func (i Int32) ToString() String {
|
||||
}
|
||||
|
||||
func (i Int32) HashCode() int32 {
|
||||
return int32(i)
|
||||
return HashInt32(int32(i))
|
||||
}
|
||||
|
||||
func (i Int32) Compare(t Int32) int {
|
||||
@ -75,3 +88,19 @@ func (i Int32) Compare(t Int32) int {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
func (i Int32) ToInt64() Int64 {
|
||||
return Int64(i)
|
||||
}
|
||||
|
||||
func (i Int32) ToUInt64() UInt64 {
|
||||
return UInt64(i)
|
||||
}
|
||||
|
||||
func (i Int32) ToFloat64() Float64 {
|
||||
return Float64(i)
|
||||
}
|
||||
|
||||
func HashInt32(i int32) int32 {
|
||||
return i
|
||||
}
|
||||
|
@ -10,25 +10,42 @@ import "strconv"
|
||||
|
||||
type Int64 int64
|
||||
|
||||
type AsInt64 interface {
|
||||
Object
|
||||
AsInt64() Int64
|
||||
}
|
||||
|
||||
func CastInt64(v any) (int64, bool) {
|
||||
switch i := v.(type) {
|
||||
case int:
|
||||
return int64(i), true
|
||||
case int8:
|
||||
return int64(i), true
|
||||
case int16:
|
||||
return int64(i), true
|
||||
case int32:
|
||||
return int64(i), true
|
||||
case int64:
|
||||
return i, true
|
||||
case AsInt64:
|
||||
return i.AsInt64().V(), true
|
||||
case uint:
|
||||
return int64(i), true
|
||||
case uint8:
|
||||
return int64(i), true
|
||||
case uint16:
|
||||
return int64(i), true
|
||||
case uint32:
|
||||
return int64(i), true
|
||||
case uint64:
|
||||
return int64(i), true
|
||||
case float32:
|
||||
return int64(i), true
|
||||
case float64:
|
||||
return int64(i), true
|
||||
case Number:
|
||||
return i.ToInt64().V(), true
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
func EqualsInt64(i1 AsInt64, i2 any) bool {
|
||||
func EqualsInt64(i1 Number, i2 any) bool {
|
||||
i2, ok := CastInt64(i2)
|
||||
return ok && i2 == i1.AsInt64().V()
|
||||
return ok && i2 == i1.ToUInt64().V()
|
||||
}
|
||||
|
||||
func (i Int64) V() int64 {
|
||||
@ -39,10 +56,6 @@ func (i *Int64) P() *int64 {
|
||||
return (*int64)(i)
|
||||
}
|
||||
|
||||
func (i Int64) AsInt64() Int64 {
|
||||
return i
|
||||
}
|
||||
|
||||
func (i Int64) String() string {
|
||||
return strconv.FormatInt(int64(i), 10)
|
||||
}
|
||||
@ -60,7 +73,7 @@ func (i Int64) ToString() String {
|
||||
}
|
||||
|
||||
func (i Int64) HashCode() int32 {
|
||||
return Hash64(&i)
|
||||
return HashInt64(int64(i))
|
||||
}
|
||||
|
||||
func (i Int64) Compare(t Int64) int {
|
||||
@ -73,3 +86,19 @@ func (i Int64) Compare(t Int64) int {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
func (i Int64) ToInt64() Int64 {
|
||||
return Int64(i)
|
||||
}
|
||||
|
||||
func (i Int64) ToUInt64() UInt64 {
|
||||
return UInt64(i)
|
||||
}
|
||||
|
||||
func (i Int64) ToFloat64() Float64 {
|
||||
return Float64(i)
|
||||
}
|
||||
|
||||
func HashInt64(i int64) int32 {
|
||||
return int32(i) ^ int32(i>>32)
|
||||
}
|
||||
|
57
lang/Int8.go
57
lang/Int8.go
@ -10,25 +10,42 @@ import "strconv"
|
||||
|
||||
type Int8 int8
|
||||
|
||||
type AsInt8 interface {
|
||||
Object
|
||||
AsInt8() Int8
|
||||
}
|
||||
|
||||
func CastInt8(v any) (int8, bool) {
|
||||
switch i := v.(type) {
|
||||
case int:
|
||||
return int8(i), true
|
||||
case int8:
|
||||
return i, true
|
||||
case AsInt8:
|
||||
return i.AsInt8().V(), true
|
||||
case int16:
|
||||
return int8(i), true
|
||||
case int32:
|
||||
return int8(i), true
|
||||
case int64:
|
||||
return int8(i), true
|
||||
case uint:
|
||||
return int8(i), true
|
||||
case uint8:
|
||||
return int8(i), true
|
||||
case uint16:
|
||||
return int8(i), true
|
||||
case uint32:
|
||||
return int8(i), true
|
||||
case uint64:
|
||||
return int8(i), true
|
||||
case float32:
|
||||
return int8(i), true
|
||||
case float64:
|
||||
return int8(i), true
|
||||
case Number:
|
||||
return int8(i.ToFloat64().V()), true
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
func EqualsInt8(i1 AsInt8, i2 any) bool {
|
||||
func EqualsInt8(i1 Number, i2 any) bool {
|
||||
i2, ok := CastInt8(i2)
|
||||
return ok && i2 == i1.AsInt8().V()
|
||||
return ok && i2 == i1.ToInt64().V()
|
||||
}
|
||||
|
||||
func (i Int8) V() int8 {
|
||||
@ -39,10 +56,6 @@ func (i *Int8) P() *int8 {
|
||||
return (*int8)(i)
|
||||
}
|
||||
|
||||
func (i Int8) AsInt8() Int8 {
|
||||
return i
|
||||
}
|
||||
|
||||
func (i Int8) String() string {
|
||||
return strconv.FormatInt(int64(i), 10)
|
||||
}
|
||||
@ -60,7 +73,7 @@ func (i Int8) ToString() String {
|
||||
}
|
||||
|
||||
func (i Int8) HashCode() int32 {
|
||||
return int32(i)
|
||||
return HashInt8(int8(i))
|
||||
}
|
||||
|
||||
func (i Int8) Compare(t Int8) int {
|
||||
@ -73,3 +86,19 @@ func (i Int8) Compare(t Int8) int {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
func (i Int8) ToInt64() Int64 {
|
||||
return Int64(i)
|
||||
}
|
||||
|
||||
func (i Int8) ToUInt64() UInt64 {
|
||||
return UInt64(i)
|
||||
}
|
||||
|
||||
func (i Int8) ToFloat64() Float64 {
|
||||
return Float64(i)
|
||||
}
|
||||
|
||||
func HashInt8(i int8) int32 {
|
||||
return HashInt32(int32(i))
|
||||
}
|
||||
|
14
lang/Number.go
Normal file
14
lang/Number.go
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2022 tursom. All rights reserved.
|
||||
* Use of this source code is governed by a GPL-3
|
||||
* license that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package lang
|
||||
|
||||
// Number interface for real number
|
||||
type Number interface {
|
||||
ToInt64() Int64
|
||||
ToUInt64() UInt64
|
||||
ToFloat64() Float64
|
||||
}
|
57
lang/UInt.go
57
lang/UInt.go
@ -10,25 +10,42 @@ import "strconv"
|
||||
|
||||
type UInt uint
|
||||
|
||||
type AsUInt interface {
|
||||
Object
|
||||
AsUInt() UInt
|
||||
}
|
||||
|
||||
func CastUInt(v any) (uint, bool) {
|
||||
switch i := v.(type) {
|
||||
case int:
|
||||
return uint(i), true
|
||||
case int8:
|
||||
return uint(i), true
|
||||
case int16:
|
||||
return uint(i), true
|
||||
case int32:
|
||||
return uint(i), true
|
||||
case int64:
|
||||
return uint(i), true
|
||||
case uint:
|
||||
return i, true
|
||||
case AsUInt:
|
||||
return i.AsUInt().V(), true
|
||||
case uint8:
|
||||
return uint(i), true
|
||||
case uint16:
|
||||
return uint(i), true
|
||||
case uint32:
|
||||
return uint(i), true
|
||||
case uint64:
|
||||
return uint(i), true
|
||||
case float32:
|
||||
return uint(i), true
|
||||
case float64:
|
||||
return uint(i), true
|
||||
case Number:
|
||||
return uint(i.ToUInt64().V()), true
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
func EqualsUInt(i1 AsUInt, i2 any) bool {
|
||||
func EqualsUInt(i1 Number, i2 any) bool {
|
||||
i2, ok := CastUInt(i2)
|
||||
return ok && i2 == i1.AsUInt().V()
|
||||
return ok && i2 == i1.ToUInt64().V()
|
||||
}
|
||||
|
||||
func (i UInt) V() uint {
|
||||
@ -39,10 +56,6 @@ func (i *UInt) P() *uint {
|
||||
return (*uint)(i)
|
||||
}
|
||||
|
||||
func (i UInt) AsUInt() UInt {
|
||||
return i
|
||||
}
|
||||
|
||||
func (i UInt) String() string {
|
||||
return strconv.FormatUint(uint64(i), 10)
|
||||
}
|
||||
@ -60,7 +73,7 @@ func (i UInt) ToString() String {
|
||||
}
|
||||
|
||||
func (i UInt) HashCode() int32 {
|
||||
return int32(i)
|
||||
return HashUInt(uint(i))
|
||||
}
|
||||
|
||||
func (i UInt) Compare(t UInt) int {
|
||||
@ -73,3 +86,19 @@ func (i UInt) Compare(t UInt) int {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
func (i UInt) ToInt64() Int64 {
|
||||
return Int64(i)
|
||||
}
|
||||
|
||||
func (i UInt) ToUInt64() UInt64 {
|
||||
return UInt64(i)
|
||||
}
|
||||
|
||||
func (i UInt) ToFloat64() Float64 {
|
||||
return Float64(i)
|
||||
}
|
||||
|
||||
func HashUInt(i uint) int32 {
|
||||
return HashInt(int(i))
|
||||
}
|
||||
|
@ -10,25 +10,42 @@ import "strconv"
|
||||
|
||||
type UInt16 uint16
|
||||
|
||||
type AsUInt16 interface {
|
||||
Object
|
||||
AsUInt16() UInt16
|
||||
}
|
||||
|
||||
func CastUInt16(v any) (uint16, bool) {
|
||||
switch i := v.(type) {
|
||||
case int:
|
||||
return uint16(i), true
|
||||
case int8:
|
||||
return uint16(i), true
|
||||
case int16:
|
||||
return uint16(i), true
|
||||
case int32:
|
||||
return uint16(i), true
|
||||
case int64:
|
||||
return uint16(i), true
|
||||
case uint:
|
||||
return uint16(i), true
|
||||
case uint8:
|
||||
return uint16(i), true
|
||||
case uint16:
|
||||
return i, true
|
||||
case AsUInt16:
|
||||
return i.AsUInt16().V(), true
|
||||
case uint32:
|
||||
return uint16(i), true
|
||||
case uint64:
|
||||
return uint16(i), true
|
||||
case float32:
|
||||
return uint16(i), true
|
||||
case float64:
|
||||
return uint16(i), true
|
||||
case Number:
|
||||
return uint16(i.ToUInt64().V()), true
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
func EqualsUInt16(i1 AsUInt16, i2 any) bool {
|
||||
func EqualsUInt16(i1 Number, i2 any) bool {
|
||||
i2, ok := CastUInt16(i2)
|
||||
return ok && i2 == i1.AsUInt16().V()
|
||||
return ok && i2 == i1.ToUInt64().V()
|
||||
}
|
||||
|
||||
func (i UInt16) V() uint16 {
|
||||
@ -39,10 +56,6 @@ func (i *UInt16) P() *uint16 {
|
||||
return (*uint16)(i)
|
||||
}
|
||||
|
||||
func (i UInt16) AsUInt16() UInt16 {
|
||||
return i
|
||||
}
|
||||
|
||||
func (i UInt16) String() string {
|
||||
return strconv.FormatUint(uint64(i), 10)
|
||||
}
|
||||
@ -60,7 +73,7 @@ func (i UInt16) ToString() String {
|
||||
}
|
||||
|
||||
func (i UInt16) HashCode() int32 {
|
||||
return int32(i)
|
||||
return HashUInt16(uint16(i))
|
||||
}
|
||||
|
||||
func (i UInt16) Compare(t UInt16) int {
|
||||
@ -73,3 +86,19 @@ func (i UInt16) Compare(t UInt16) int {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
func (i UInt16) ToInt64() Int64 {
|
||||
return Int64(i)
|
||||
}
|
||||
|
||||
func (i UInt16) ToUInt64() UInt64 {
|
||||
return UInt64(i)
|
||||
}
|
||||
|
||||
func (i UInt16) ToFloat64() Float64 {
|
||||
return Float64(i)
|
||||
}
|
||||
|
||||
func HashUInt16(i uint16) int32 {
|
||||
return HashUInt32(uint32(i))
|
||||
}
|
||||
|
@ -10,25 +10,42 @@ import "strconv"
|
||||
|
||||
type UInt32 uint32
|
||||
|
||||
type AsUInt32 interface {
|
||||
Object
|
||||
AsUInt32() UInt32
|
||||
}
|
||||
|
||||
func CastUInt32(v any) (uint32, bool) {
|
||||
switch i := v.(type) {
|
||||
case int:
|
||||
return uint32(i), true
|
||||
case int8:
|
||||
return uint32(i), true
|
||||
case int16:
|
||||
return uint32(i), true
|
||||
case int32:
|
||||
return uint32(i), true
|
||||
case int64:
|
||||
return uint32(i), true
|
||||
case uint:
|
||||
return uint32(i), true
|
||||
case uint8:
|
||||
return uint32(i), true
|
||||
case uint16:
|
||||
return uint32(i), true
|
||||
case uint32:
|
||||
return i, true
|
||||
case AsUInt32:
|
||||
return i.AsUInt32().V(), true
|
||||
case uint64:
|
||||
return uint32(i), true
|
||||
case float32:
|
||||
return uint32(i), true
|
||||
case float64:
|
||||
return uint32(i), true
|
||||
case Number:
|
||||
return uint32(i.ToUInt64().V()), true
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
func EqualsUInt32(i1 AsUInt32, i2 any) bool {
|
||||
func EqualsUInt32(i1 Number, i2 any) bool {
|
||||
i2, ok := CastUInt32(i2)
|
||||
return ok && i2 == i1.AsUInt32().V()
|
||||
return ok && i2 == i1.ToUInt64().V()
|
||||
}
|
||||
|
||||
func (i UInt32) V() uint32 {
|
||||
@ -39,10 +56,6 @@ func (i *UInt32) P() *uint32 {
|
||||
return (*uint32)(i)
|
||||
}
|
||||
|
||||
func (i UInt32) AsUInt32() UInt32 {
|
||||
return i
|
||||
}
|
||||
|
||||
func (i UInt32) String() string {
|
||||
return strconv.FormatUint(uint64(i), 10)
|
||||
}
|
||||
@ -60,7 +73,7 @@ func (i UInt32) ToString() String {
|
||||
}
|
||||
|
||||
func (i UInt32) HashCode() int32 {
|
||||
return int32(i)
|
||||
return HashUInt32(uint32(i))
|
||||
}
|
||||
|
||||
func (i UInt32) Compare(t UInt32) int {
|
||||
@ -73,3 +86,19 @@ func (i UInt32) Compare(t UInt32) int {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
func (i UInt32) ToInt64() Int64 {
|
||||
return Int64(i)
|
||||
}
|
||||
|
||||
func (i UInt32) ToUInt64() UInt64 {
|
||||
return UInt64(i)
|
||||
}
|
||||
|
||||
func (i UInt32) ToFloat64() Float64 {
|
||||
return Float64(i)
|
||||
}
|
||||
|
||||
func HashUInt32(i uint32) int32 {
|
||||
return HashInt32(int32(i))
|
||||
}
|
||||
|
@ -10,25 +10,42 @@ import "strconv"
|
||||
|
||||
type UInt64 uint64
|
||||
|
||||
type AsUInt64 interface {
|
||||
Object
|
||||
AsUInt64() UInt64
|
||||
}
|
||||
|
||||
func CastUInt64(v any) (uint64, bool) {
|
||||
switch i := v.(type) {
|
||||
case int:
|
||||
return uint64(i), true
|
||||
case int8:
|
||||
return uint64(i), true
|
||||
case int16:
|
||||
return uint64(i), true
|
||||
case int32:
|
||||
return uint64(i), true
|
||||
case int64:
|
||||
return uint64(i), true
|
||||
case uint:
|
||||
return uint64(i), true
|
||||
case uint8:
|
||||
return uint64(i), true
|
||||
case uint16:
|
||||
return uint64(i), true
|
||||
case uint32:
|
||||
return uint64(i), true
|
||||
case uint64:
|
||||
return i, true
|
||||
case AsUInt64:
|
||||
return i.AsUInt64().V(), true
|
||||
return uint64(i), true
|
||||
case float32:
|
||||
return uint64(i), true
|
||||
case float64:
|
||||
return uint64(i), true
|
||||
case Number:
|
||||
return i.ToUInt64().V(), true
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
func EqualsUInt64(i1 AsUInt64, i2 any) bool {
|
||||
func EqualsUInt64(i1 Number, i2 any) bool {
|
||||
i2, ok := CastUInt64(i2)
|
||||
return ok && i2 == i1.AsUInt64().V()
|
||||
return ok && i2 == i1.ToUInt64().V()
|
||||
}
|
||||
|
||||
func (i UInt64) V() uint64 {
|
||||
@ -39,10 +56,6 @@ func (i *UInt64) P() *uint64 {
|
||||
return (*uint64)(i)
|
||||
}
|
||||
|
||||
func (i UInt64) AsUInt64() UInt64 {
|
||||
return i
|
||||
}
|
||||
|
||||
func (i UInt64) String() string {
|
||||
return strconv.FormatUint(uint64(i), 10)
|
||||
}
|
||||
@ -60,7 +73,7 @@ func (i UInt64) ToString() String {
|
||||
}
|
||||
|
||||
func (i UInt64) HashCode() int32 {
|
||||
return Hash64(&i)
|
||||
return HashUInt64(uint64(i))
|
||||
}
|
||||
|
||||
func (i UInt64) Compare(t UInt64) int {
|
||||
@ -73,3 +86,19 @@ func (i UInt64) Compare(t UInt64) int {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
func (i UInt64) ToInt64() Int64 {
|
||||
return Int64(i)
|
||||
}
|
||||
|
||||
func (i UInt64) ToUInt64() UInt64 {
|
||||
return i
|
||||
}
|
||||
|
||||
func (i UInt64) ToFloat64() Float64 {
|
||||
return Float64(i)
|
||||
}
|
||||
|
||||
func HashUInt64(i uint64) int32 {
|
||||
return HashInt64(int64(i))
|
||||
}
|
||||
|
@ -10,25 +10,42 @@ import "strconv"
|
||||
|
||||
type UInt8 uint8
|
||||
|
||||
type AsUInt8 interface {
|
||||
Object
|
||||
AsUInt8() UInt8
|
||||
}
|
||||
|
||||
func CastUInt8(v any) (uint8, bool) {
|
||||
switch i := v.(type) {
|
||||
case int:
|
||||
return uint8(i), true
|
||||
case int8:
|
||||
return uint8(i), true
|
||||
case int16:
|
||||
return uint8(i), true
|
||||
case int32:
|
||||
return uint8(i), true
|
||||
case int64:
|
||||
return uint8(i), true
|
||||
case uint:
|
||||
return uint8(i), true
|
||||
case uint8:
|
||||
return i, true
|
||||
case AsUInt8:
|
||||
return i.AsUInt8().V(), true
|
||||
case uint16:
|
||||
return uint8(i), true
|
||||
case uint32:
|
||||
return uint8(i), true
|
||||
case uint64:
|
||||
return uint8(i), true
|
||||
case float32:
|
||||
return uint8(i), true
|
||||
case float64:
|
||||
return uint8(i), true
|
||||
case Number:
|
||||
return uint8(i.ToUInt64().V()), true
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
func EqualsUInt8(i1 AsUInt8, i2 any) bool {
|
||||
func EqualsUInt8(i1 Number, i2 any) bool {
|
||||
i2, ok := CastUInt8(i2)
|
||||
return ok && i2 == i1.AsUInt8().V()
|
||||
return ok && i2 == i1.ToUInt64().V()
|
||||
}
|
||||
|
||||
func (i UInt8) V() uint8 {
|
||||
@ -39,10 +56,6 @@ func (i *UInt8) P() *uint8 {
|
||||
return (*uint8)(i)
|
||||
}
|
||||
|
||||
func (i UInt8) AsUInt8() UInt8 {
|
||||
return i
|
||||
}
|
||||
|
||||
func (i UInt8) String() string {
|
||||
return strconv.FormatUint(uint64(i), 10)
|
||||
}
|
||||
@ -60,7 +73,7 @@ func (i UInt8) ToString() String {
|
||||
}
|
||||
|
||||
func (i UInt8) HashCode() int32 {
|
||||
return int32(i)
|
||||
return HashUInt8(uint8(i))
|
||||
}
|
||||
|
||||
func (i UInt8) Compare(t UInt8) int {
|
||||
@ -73,3 +86,19 @@ func (i UInt8) Compare(t UInt8) int {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
func (i UInt8) ToInt64() Int64 {
|
||||
return Int64(i)
|
||||
}
|
||||
|
||||
func (i UInt8) ToUInt64() UInt64 {
|
||||
return UInt64(i)
|
||||
}
|
||||
|
||||
func (i UInt8) ToFloat64() Float64 {
|
||||
return Float64(i)
|
||||
}
|
||||
|
||||
func HashUInt8(i uint8) int32 {
|
||||
return HashUInt32(uint32(i))
|
||||
}
|
||||
|
89
lang/atomic/Float32.go
Normal file
89
lang/atomic/Float32.go
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2022 tursom. All rights reserved.
|
||||
* Use of this source code is governed by a GPL-3
|
||||
* license that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package atomic
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
"unsafe"
|
||||
|
||||
"github.com/tursom/GoCollections/lang"
|
||||
)
|
||||
|
||||
type Float32 float32
|
||||
|
||||
func (v *Float32) P() *float32 {
|
||||
return (*float32)(v)
|
||||
}
|
||||
|
||||
func (v *Float32) pint32() *int32 {
|
||||
return (*int32)(unsafe.Pointer(v))
|
||||
}
|
||||
|
||||
func (v *Float32) Load() (val float32) {
|
||||
return intToFloat32(atomic.LoadInt32(v.pint32()))
|
||||
}
|
||||
|
||||
func (v *Float32) Store(val float32) {
|
||||
atomic.StoreInt32(v.pint32(), floatToInt32(val))
|
||||
}
|
||||
|
||||
func (v *Float32) Swap(new float32) (old float32) {
|
||||
i := atomic.SwapInt32(v.pint32(), floatToInt32(new))
|
||||
return intToFloat32(i)
|
||||
}
|
||||
|
||||
func (v *Float32) CompareAndSwap(old, new float32) (swapped bool) {
|
||||
return atomic.CompareAndSwapInt32(v.pint32(), floatToInt32(old), floatToInt32(new))
|
||||
}
|
||||
|
||||
func (v *Float32) Add(f float32) (new float32) {
|
||||
old := float32(*v)
|
||||
new = old + f
|
||||
for !v.CompareAndSwap(old, new) {
|
||||
old = float32(*v)
|
||||
new = old + f
|
||||
}
|
||||
|
||||
return new
|
||||
}
|
||||
|
||||
func (v *Float32) String() string {
|
||||
return strconv.FormatFloat(float64(*v), 'e', -1, 32)
|
||||
}
|
||||
|
||||
func (v *Float32) AsObject() lang.Object {
|
||||
return v
|
||||
}
|
||||
|
||||
func (v *Float32) Equals(o lang.Object) bool {
|
||||
return lang.EqualsFloat32(v, o)
|
||||
}
|
||||
|
||||
func (v *Float32) HashCode() int32 {
|
||||
return lang.Hash32(v)
|
||||
}
|
||||
|
||||
func (v *Float32) ToInt64() lang.Int64 {
|
||||
return lang.Int64(*v)
|
||||
}
|
||||
|
||||
func (v *Float32) ToUInt64() lang.UInt64 {
|
||||
return lang.UInt64(*v)
|
||||
}
|
||||
|
||||
func (v *Float32) ToFloat64() lang.Float64 {
|
||||
return lang.Float64(*v)
|
||||
}
|
||||
|
||||
func floatToInt32(f float32) int32 {
|
||||
return *(*int32)(unsafe.Pointer(&f))
|
||||
}
|
||||
|
||||
func intToFloat32(f int32) float32 {
|
||||
return *(*float32)(unsafe.Pointer(&f))
|
||||
}
|
89
lang/atomic/Float64.go
Normal file
89
lang/atomic/Float64.go
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2022 tursom. All rights reserved.
|
||||
* Use of this source code is governed by a GPL-3
|
||||
* license that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package atomic
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
"unsafe"
|
||||
|
||||
"github.com/tursom/GoCollections/lang"
|
||||
)
|
||||
|
||||
type Float64 float64
|
||||
|
||||
func (v *Float64) P() *float64 {
|
||||
return (*float64)(v)
|
||||
}
|
||||
|
||||
func (v *Float64) pint64() *int64 {
|
||||
return (*int64)(unsafe.Pointer(v))
|
||||
}
|
||||
|
||||
func (v *Float64) Load() (val float64) {
|
||||
return intToFloat64(atomic.LoadInt64(v.pint64()))
|
||||
}
|
||||
|
||||
func (v *Float64) Store(val float64) {
|
||||
atomic.StoreInt64(v.pint64(), floatToInt64(val))
|
||||
}
|
||||
|
||||
func (v *Float64) Swap(new float64) (old float64) {
|
||||
i := atomic.SwapInt64(v.pint64(), floatToInt64(new))
|
||||
return intToFloat64(i)
|
||||
}
|
||||
|
||||
func (v *Float64) CompareAndSwap(old, new float64) (swapped bool) {
|
||||
return atomic.CompareAndSwapInt64(v.pint64(), floatToInt64(old), floatToInt64(new))
|
||||
}
|
||||
|
||||
func (v *Float64) Add(f float64) (new float64) {
|
||||
old := float64(*v)
|
||||
new = old + f
|
||||
for !v.CompareAndSwap(old, new) {
|
||||
old = float64(*v)
|
||||
new = old + f
|
||||
}
|
||||
|
||||
return new
|
||||
}
|
||||
|
||||
func (v *Float64) String() string {
|
||||
return strconv.FormatFloat(float64(*v), 'e', -1, 64)
|
||||
}
|
||||
|
||||
func (v *Float64) AsObject() lang.Object {
|
||||
return v
|
||||
}
|
||||
|
||||
func (v *Float64) Equals(o lang.Object) bool {
|
||||
return lang.EqualsFloat64(v, o)
|
||||
}
|
||||
|
||||
func (v *Float64) HashCode() int32 {
|
||||
return lang.Hash64(v)
|
||||
}
|
||||
|
||||
func (v *Float64) ToInt64() lang.Int64 {
|
||||
return lang.Int64(*v)
|
||||
}
|
||||
|
||||
func (v *Float64) ToUInt64() lang.UInt64 {
|
||||
return lang.UInt64(*v)
|
||||
}
|
||||
|
||||
func (v *Float64) ToFloat64() lang.Float64 {
|
||||
return lang.Float64(*v)
|
||||
}
|
||||
|
||||
func floatToInt64(f float64) int64 {
|
||||
return *(*int64)(unsafe.Pointer(&f))
|
||||
}
|
||||
|
||||
func intToFloat64(f int64) float64 {
|
||||
return *(*float64)(unsafe.Pointer(&f))
|
||||
}
|
@ -7,7 +7,7 @@
|
||||
package atomic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/tursom/GoCollections/lang"
|
||||
@ -15,26 +15,6 @@ import (
|
||||
|
||||
type Int32 int32
|
||||
|
||||
func (v *Int32) AsInt32() lang.Int32 {
|
||||
return lang.Int32(*v)
|
||||
}
|
||||
|
||||
func (v *Int32) String() string {
|
||||
return fmt.Sprint(*v)
|
||||
}
|
||||
|
||||
func (v *Int32) AsObject() lang.Object {
|
||||
return v
|
||||
}
|
||||
|
||||
func (v *Int32) Equals(o lang.Object) bool {
|
||||
return lang.EqualsInt32(v, o)
|
||||
}
|
||||
|
||||
func (v *Int32) HashCode() int32 {
|
||||
return v.AsInt32().V()
|
||||
}
|
||||
|
||||
func (v *Int32) P() *int32 {
|
||||
return (*int32)(v)
|
||||
}
|
||||
@ -70,3 +50,31 @@ func (v *Int32) SetBit(bit int, up bool) bool {
|
||||
func (v *Int32) CompareAndSwapBit(bit int, old, new bool) bool {
|
||||
return CompareAndSwapBit(CompareAndSwapInt32, v.P(), bit, old, new)
|
||||
}
|
||||
|
||||
func (v *Int32) String() string {
|
||||
return strconv.FormatInt(int64(*v), 10)
|
||||
}
|
||||
|
||||
func (v *Int32) AsObject() lang.Object {
|
||||
return v
|
||||
}
|
||||
|
||||
func (v *Int32) Equals(o lang.Object) bool {
|
||||
return lang.EqualsInt32(v, o)
|
||||
}
|
||||
|
||||
func (v *Int32) HashCode() int32 {
|
||||
return lang.Hash32(v)
|
||||
}
|
||||
|
||||
func (v *Int32) ToInt64() lang.Int64 {
|
||||
return lang.Int64(*v)
|
||||
}
|
||||
|
||||
func (v *Int32) ToUInt64() lang.UInt64 {
|
||||
return lang.UInt64(*v)
|
||||
}
|
||||
|
||||
func (v *Int32) ToFloat64() lang.Float64 {
|
||||
return lang.Float64(*v)
|
||||
}
|
||||
|
@ -7,7 +7,10 @@
|
||||
package atomic
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/tursom/GoCollections/lang"
|
||||
)
|
||||
|
||||
type Int64 int64
|
||||
@ -47,3 +50,31 @@ func (v *Int64) SetBit(bit int, up bool) bool {
|
||||
func (v *Int64) CompareAndSwapBit(bit int, old, new bool) bool {
|
||||
return CompareAndSwapBit(CompareAndSwapInt64, v.P(), bit, old, new)
|
||||
}
|
||||
|
||||
func (v *Int64) String() string {
|
||||
return strconv.FormatInt(int64(*v), 10)
|
||||
}
|
||||
|
||||
func (v *Int64) AsObject() lang.Object {
|
||||
return v
|
||||
}
|
||||
|
||||
func (v *Int64) Equals(o lang.Object) bool {
|
||||
return lang.EqualsInt64(v, o)
|
||||
}
|
||||
|
||||
func (v *Int64) HashCode() int32 {
|
||||
return int32(*v) ^ int32(*v>>32)
|
||||
}
|
||||
|
||||
func (v *Int64) ToInt64() lang.Int64 {
|
||||
return lang.Int64(*v)
|
||||
}
|
||||
|
||||
func (v *Int64) ToUInt64() lang.UInt64 {
|
||||
return lang.UInt64(*v)
|
||||
}
|
||||
|
||||
func (v *Int64) ToFloat64() lang.Float64 {
|
||||
return lang.Float64(*v)
|
||||
}
|
||||
|
@ -7,7 +7,10 @@
|
||||
package atomic
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/tursom/GoCollections/lang"
|
||||
)
|
||||
|
||||
type UInt32 uint32
|
||||
@ -47,3 +50,31 @@ func (v *UInt32) SetBit(bit int, up bool) bool {
|
||||
func (v *UInt32) CompareAndSwapBit(bit int, old, new bool) bool {
|
||||
return CompareAndSwapBit(CompareAndSwapUInt32, v.P(), bit, old, new)
|
||||
}
|
||||
|
||||
func (v *UInt32) String() string {
|
||||
return strconv.FormatUint(uint64(*v), 10)
|
||||
}
|
||||
|
||||
func (v *UInt32) AsObject() lang.Object {
|
||||
return v
|
||||
}
|
||||
|
||||
func (v *UInt32) Equals(o lang.Object) bool {
|
||||
return lang.EqualsUInt32(v, o)
|
||||
}
|
||||
|
||||
func (v *UInt32) HashCode() int32 {
|
||||
return int32(*v)
|
||||
}
|
||||
|
||||
func (v *UInt32) ToInt64() lang.Int64 {
|
||||
return lang.Int64(*v)
|
||||
}
|
||||
|
||||
func (v *UInt32) ToUInt64() lang.UInt64 {
|
||||
return lang.UInt64(*v)
|
||||
}
|
||||
|
||||
func (v *UInt32) ToFloat64() lang.Float64 {
|
||||
return lang.Float64(*v)
|
||||
}
|
||||
|
@ -7,7 +7,10 @@
|
||||
package atomic
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/tursom/GoCollections/lang"
|
||||
)
|
||||
|
||||
type UInt64 uint64
|
||||
@ -47,3 +50,31 @@ func (v *UInt64) SetBit(bit int, up bool) bool {
|
||||
func (v *UInt64) CompareAndSwapBit(bit int, old, new bool) bool {
|
||||
return CompareAndSwapBit(CompareAndSwapUInt64, v.P(), bit, old, new)
|
||||
}
|
||||
|
||||
func (v *UInt64) String() string {
|
||||
return strconv.FormatUint(uint64(*v), 10)
|
||||
}
|
||||
|
||||
func (v *UInt64) AsObject() lang.Object {
|
||||
return v
|
||||
}
|
||||
|
||||
func (v *UInt64) Equals(o lang.Object) bool {
|
||||
return lang.EqualsUInt64(v, o)
|
||||
}
|
||||
|
||||
func (v *UInt64) HashCode() int32 {
|
||||
return int32(*v) ^ int32(*v>>32)
|
||||
}
|
||||
|
||||
func (v *UInt64) ToInt64() lang.Int64 {
|
||||
return lang.Int64(*v)
|
||||
}
|
||||
|
||||
func (v *UInt64) ToUInt64() lang.UInt64 {
|
||||
return lang.UInt64(*v)
|
||||
}
|
||||
|
||||
func (v *UInt64) ToFloat64() lang.Float64 {
|
||||
return lang.Float64(*v)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user