Skip to content

Commit 4a31e89

Browse files
update use case
1 parent ad08525 commit 4a31e89

File tree

9 files changed

+87
-18
lines changed

9 files changed

+87
-18
lines changed

.vscode/launch.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// IntelliSense를 사용하여 가능한 특성에 대해 알아보세요.
3+
// 기존 특성에 대한 설명을 보려면 가리킵니다.
4+
// 자세한 내용을 보려면 https://go.microsoft.com/fwlink/?linkid=830387을(를) 방문하세요.
5+
"version": "0.2.0",
6+
"configurations": [
7+
8+
{
9+
"name": "Launch Package",
10+
"type": "go",
11+
"request": "launch",
12+
"mode": "auto",
13+
"program": "${fileDirname}"
14+
}
15+
]
16+
}

README.md

+31
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,37 @@
55
- Supports up to 96 integers and 32 decimal places
66
- implement ericlagergren/decimal ( github.com/ericlagergren/decimal )
77

8+
9+
## Quick Start
10+
11+
```go
12+
13+
package main
14+
15+
import (
16+
"fmt"
17+
18+
"github.com/gokch/snum_sort/snum"
19+
"github.com/gokch/snum_sort/sort"
20+
)
21+
22+
func main() {
23+
sn1 := snum.New("123456789.987654321")
24+
fmt.Println("snum :", sn1)
25+
26+
st1 := sort.New(sn1)
27+
fmt.Println("sort :", st1)
28+
29+
enc, _ := st1.MarshalJSON()
30+
fmt.Println("json :", enc)
31+
32+
st1New := sort.New(0)
33+
st1New.UnmarshalJSON(enc)
34+
fmt.Println("new :", st1New)
35+
}
36+
37+
```
38+
839
# max length
940
- positive : 65 byte (header 1 bt + body 64 bt)
1041
- negative : 66 byte (header 1 bt + body 64 bt + 0xFF 1 bt)

main.go

+23-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
1-
package snum_sort
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/gokch/snum_sort/snum"
7+
"github.com/gokch/snum_sort/sort"
8+
)
9+
10+
func main() {
11+
sn1 := snum.New("123456789.987654321")
12+
fmt.Println("snum :", sn1)
13+
14+
st1 := sort.New(sn1)
15+
fmt.Println("sort :", st1)
16+
17+
enc, _ := st1.MarshalJSON()
18+
fmt.Println("json :", string(enc))
19+
20+
st1New := sort.New(0)
21+
st1New.UnmarshalJSON(enc)
22+
fmt.Println("new :", st1New)
23+
}

snum/get_set.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (t *Snum) TrimDigit(lenInteger, lenDecimal int) error {
118118
// 후처리 - 정수
119119
if lenIntegerNow > lenInteger {
120120
errInteger = fmt.Errorf("Integer limit exceeded | input : %d | limit : %d", lenIntegerNow, lenInteger) // 에러 처리
121-
pt_snum := NewSnum(0)
121+
pt_snum := New(0)
122122

123123
pt_snum.decimal.SetUint64(10)
124124
pt_snum.Pow(int64(lenInteger))

snum/snum.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type SnumConst interface {
88
*Snum | int | int32 | int64 | uint | uint32 | uint64 | string
99
}
1010

11-
func NewSnum[T SnumConst](num T) *Snum {
11+
func New[T SnumConst](num T) *Snum {
1212
snum := &Snum{}
1313
snum.Init()
1414

@@ -66,7 +66,7 @@ func (t *Snum) Init() {
6666
}
6767

6868
func (t *Snum) Copy() *Snum {
69-
ret := NewSnum(0)
69+
ret := New(0)
7070
ret.decimal.Copy(t.decimal)
7171
return ret
7272
}

snum/snum_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ import (
77

88
func Test_snum(t *testing.T) {
99
{
10-
snum := NewSnum(0)
10+
snum := New(0)
1111
fmt.Println(snum)
1212
}
1313
{
1414
var num int = -1
15-
snum := NewSnum(num)
15+
snum := New(num)
1616
fmt.Println(snum.String())
1717
}
1818
{
1919
str := "1.2345"
20-
snum := NewSnum(str)
20+
snum := New(str)
2121
fmt.Println(snum.String())
2222
}
2323
{
24-
snum := NewSnum(1)
25-
snum2 := NewSnum(snum)
24+
snum := New(1)
25+
snum2 := New(snum)
2626
fmt.Println(snum2.String())
2727
}
2828
}

snum/util.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ import (
55
)
66

77
func (t *Snum) IsZero() bool {
8-
if t.Cmp(NewSnum(0)) != 0 {
8+
if t.Cmp(New(0)) != 0 {
99
return false
1010
}
1111
return true
1212
}
1313

1414
func (t *Snum) IsZeroUnder() bool {
15-
if t.Cmp(NewSnum(0)) < 0 {
15+
if t.Cmp(New(0)) < 0 {
1616
return false
1717
}
1818
return true
1919
}
2020

2121
func (t *Snum) IsZeroOver() bool {
22-
if t.Cmp(NewSnum(0)) > 0 {
22+
if t.Cmp(New(0)) > 0 {
2323
return false
2424
}
2525
return true

sort/sort.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"github.com/gokch/snum_sort/snum"
99
)
1010

11-
func NewSnumSort[T snum.SnumConst](num T) *SnumSort {
11+
func New[T snum.SnumConst](num T) *SnumSort {
1212
return &SnumSort{
13-
Snum: *snum.NewSnum(num),
13+
Snum: *snum.New(num),
1414
}
1515
}
1616

sort/sort_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
// string -> bigint -> binary -> bigint -> string
1717
func TestSort_encode_decode(t *testing.T) {
1818
fn := func(input string) {
19-
numSort := NewSnumSort(input)
19+
numSort := New(input)
2020

2121
enc := numSort.Encode()
2222
err := numSort.Decode(enc)
@@ -186,7 +186,7 @@ func Test_sort(t *testing.T) {
186186
sorts := make([]*Input, 0, 100)
187187

188188
input := func(snum string) {
189-
sorted := NewSnumSort(snum)
189+
sorted := New(snum)
190190
bt := sorted.Encode()
191191

192192
data := &Input{snum: snum, encode: bt}
@@ -277,13 +277,13 @@ func TestSort_header(t *testing.T) {
277277

278278
func TestSort_json(t *testing.T) {
279279
fn_test := func(sn string) {
280-
snumSort := NewSnumSort(snum.NewSnum(sn))
280+
snumSort := New(snum.New(sn))
281281

282282
enc, err := json.MarshalIndent(&snumSort, "", "\t")
283283
fmt.Println(sn, string(enc))
284284
require.NoError(t, err)
285285

286-
snumSortNew := NewSnumSort(snum.NewSnum(0))
286+
snumSortNew := New(snum.New(0))
287287
err = json.Unmarshal(enc, &snumSortNew)
288288
require.NoError(t, err)
289289

0 commit comments

Comments
 (0)