github.com/tursom/GoCollections@v0.3.10/lang/atomic/UInt64.go (about) 1 /* 2 * Copyright (c) 2022 tursom. All rights reserved. 3 * Use of this source code is governed by a GPL-3 4 * license that can be found in the LICENSE file. 5 */ 6 7 package atomic 8 9 import ( 10 "strconv" 11 "sync/atomic" 12 13 "github.com/tursom/GoCollections/lang" 14 ) 15 16 type UInt64 uint64 17 18 func (v *UInt64) P() *uint64 { 19 return (*uint64)(v) 20 } 21 22 func (v *UInt64) Load() (val uint64) { 23 return atomic.LoadUint64(v.P()) 24 } 25 26 func (v *UInt64) Store(val uint64) { 27 atomic.StoreUint64(v.P(), val) 28 } 29 30 func (v *UInt64) Swap(new uint64) (old uint64) { 31 return atomic.SwapUint64(v.P(), new) 32 } 33 34 func (v *UInt64) CompareAndSwap(old, new uint64) (swapped bool) { 35 return atomic.CompareAndSwapUint64(v.P(), old, new) 36 } 37 38 func (v *UInt64) Add(i uint64) (new uint64) { 39 return atomic.AddUint64(v.P(), i) 40 } 41 42 func (v *UInt64) BitLength() int { 43 return 64 44 } 45 46 func (v *UInt64) SetBit(bit int, up bool) bool { 47 return SetBit(CompareAndSwapUInt64, v.P(), bit, up) 48 } 49 50 func (v *UInt64) CompareAndSwapBit(bit int, old, new bool) bool { 51 return CompareAndSwapBit(CompareAndSwapUInt64, v.P(), bit, old, new) 52 } 53 54 func (v *UInt64) String() string { 55 return strconv.FormatUint(uint64(*v), 10) 56 } 57 58 func (v *UInt64) AsObject() lang.Object { 59 return v 60 } 61 62 func (v *UInt64) Equals(o lang.Object) bool { 63 return lang.EqualsUInt64(v, o) 64 } 65 66 func (v *UInt64) HashCode() int32 { 67 return int32(*v) ^ int32(*v>>32) 68 } 69 70 func (v *UInt64) ToInt64() lang.Int64 { 71 return lang.Int64(*v) 72 } 73 74 func (v *UInt64) ToUInt64() lang.UInt64 { 75 return lang.UInt64(*v) 76 } 77 78 func (v *UInt64) ToFloat64() lang.Float64 { 79 return lang.Float64(*v) 80 }