Skip to content

Commit

Permalink
Merge pull request #77 from myyrakle/feat/#44
Browse files Browse the repository at this point in the history
[#44] VecDeque
  • Loading branch information
myyrakle authored Nov 2, 2023
2 parents 44672b4 + 0030930 commit 50cb9f4
Show file tree
Hide file tree
Showing 3 changed files with 709 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# gost

![](https://img.shields.io/badge/language-Go-00ADD8) ![](https://img.shields.io/badge/version-v0.7.3-brightgreen) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
![](https://img.shields.io/badge/language-Go-00ADD8) ![](https://img.shields.io/badge/version-v0.8.0-brightgreen) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)

![](./etc/gorris.jpg)

Expand All @@ -11,7 +11,7 @@ Experience the true taste of Rust in Go
## Install

```
go get github.com/myyrakle/gost@v0.7.3
go get github.com/myyrakle/gost@v0.8.0
```

## Example
Expand Down
204 changes: 204 additions & 0 deletions ops.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package gost

import "math"

// Add is a trait for types that support addition.
type Add[T any] interface {
Add(rhs T) T
Expand Down Expand Up @@ -567,3 +569,205 @@ func (self *Complex64) DivAssign(rhs Complex64) {
func (self *Complex128) DivAssign(rhs Complex128) {
*self /= rhs
}

// Wrapping (modular) addition. Computes self + rhs, wrapping around at the boundary of the type.
func (self ISize) WrappingAdd(rhs ISize) ISize {
result := self + rhs

if result < self || result < rhs {
// Overflow occurred, wrap around
result = result - ISize(math.MaxInt) - 1
}
return result
}

func (self I8) WrappingAdd(rhs I8) I8 {
result := self + rhs

if result < self || result < rhs {
// Overflow occurred, wrap around
result = result - I8(math.MaxInt8) - 1
}
return result
}

func (self I16) WrappingAdd(rhs I16) I16 {
result := self + rhs

if result < self || result < rhs {
// Overflow occurred, wrap around
result = result - I16(math.MaxInt16) - 1
}
return result
}

func (self I32) WrappingAdd(rhs I32) I32 {
result := self + rhs

if result < self || result < rhs {
// Overflow occurred, wrap around
result = result - I32(math.MaxInt32) - 1
}
return result
}

func (self I64) WrappingAdd(rhs I64) I64 {
result := self + rhs

if result < self || result < rhs {
// Overflow occurred, wrap around
result = result - I64(math.MaxInt64) - 1
}
return result
}

func (self USize) WrappingAdd(rhs USize) USize {
result := self + rhs

if result < self || result < rhs {
// Overflow occurred, wrap around
result = result - USize(math.MaxUint) - 1
}
return result
}

func (self U8) WrappingAdd(rhs U8) U8 {
result := self + rhs

if result < self || result < rhs {
// Overflow occurred, wrap around
result = result - U8(math.MaxUint8) - 1
}
return result
}

func (self U16) WrappingAdd(rhs U16) U16 {
result := self + rhs

if result < self || result < rhs {
// Overflow occurred, wrap around
result = result - U16(math.MaxUint16) - 1
}
return result
}

func (self U32) WrappingAdd(rhs U32) U32 {
result := self + rhs

if result < self || result < rhs {
// Overflow occurred, wrap around
result = result - U32(math.MaxUint32) - 1
}
return result
}

func (self U64) WrappingAdd(rhs U64) U64 {
result := self + rhs

if result < self || result < rhs {
// Overflow occurred, wrap around
result = result - U64(math.MaxUint64) - 1
}
return result
}

// Wrapping (modular) subtraction. Computes self - rhs, wrapping around at the boundary of the type.
func (self ISize) WrappingSub(rhs ISize) ISize {
result := self - rhs

if result > self || result > rhs {
// Overflow occurred, wrap around
result = result + ISize(math.MaxInt) + 1
}
return result
}

func (self I8) WrappingSub(rhs I8) I8 {
result := self - rhs

if result > self || result > rhs {
// Overflow occurred, wrap around
result = result + I8(math.MaxInt8) + 1
}
return result
}

func (self I16) WrappingSub(rhs I16) I16 {
result := self - rhs

if result > self || result > rhs {
// Overflow occurred, wrap around
result = result + I16(math.MaxInt16) + 1
}
return result
}

func (self I32) WrappingSub(rhs I32) I32 {
result := self - rhs

if result > self || result > rhs {
// Overflow occurred, wrap around
result = result + I32(math.MaxInt32) + 1
}
return result
}

func (self I64) WrappingSub(rhs I64) I64 {
result := self - rhs

if result > self || result > rhs {
// Overflow occurred, wrap around
result = result + I64(math.MaxInt64) + 1
}
return result
}

func (self USize) WrappingSub(rhs USize) USize {
result := self - rhs

if result > self || result > rhs {
// Overflow occurred, wrap around
result = result + USize(math.MaxUint) + 1
}
return result
}

func (self U8) WrappingSub(rhs U8) U8 {
result := self - rhs

if result > self || result > rhs {
// Overflow occurred, wrap around
result = result + U8(math.MaxUint8) + 1
}
return result
}

func (self U16) WrappingSub(rhs U16) U16 {
result := self - rhs

if result > self || result > rhs {
// Overflow occurred, wrap around
result = result + U16(math.MaxUint16) + 1
}
return result
}

func (self U32) WrappingSub(rhs U32) U32 {
result := self - rhs

if result > self || result > rhs {
// Overflow occurred, wrap around
result = result + U32(math.MaxUint32) + 1
}
return result
}

func (self U64) WrappingSub(rhs U64) U64 {
result := self - rhs

if result > self || result > rhs {
// Overflow occurred, wrap around
result = result + U64(math.MaxUint64) + 1
}
return result
}
Loading

0 comments on commit 50cb9f4

Please sign in to comment.