This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ratelimit | |
import ( | |
"io" | |
"time" | |
) | |
// New 创建一个限数器 | |
// rate 速度,rate/每秒 | |
func New(rate int64) *Limiter { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package snowflake | |
import ( | |
"encoding/base64" | |
"encoding/binary" | |
"errors" | |
"fmt" | |
"strconv" | |
"sync" | |
"time" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package rabbitmq | |
import ( | |
"encoding/json" | |
"errors" | |
"fmt" | |
"github.com/sirupsen/logrus" | |
"github.com/streadway/amqp" | |
"google.golang.org/protobuf/proto" | |
"time" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package expiremap | |
import ( | |
"sort" | |
"sync" | |
"time" | |
) | |
type val struct { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pachage heapsort | |
func Sort[T constraints.Ordered](buf []T) { | |
n := len(buf) | |
for i := (n - 1) / 2; i >= 0; i-- { | |
minHeapFixdown[T](buf, i, n) | |
} | |
for i := n - 1; i > 0; i-- { | |
temp := buf[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package shellsort | |
func Sort[T constraints.Ordered](buf []T) { | |
length := len(buf) | |
incre := length | |
for { | |
incre /= 2 | |
for k := 0; k < incre; k++ { | |
for i := k + incre; i < length; i += incre { | |
for j := i; j > k; j -= incre { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package quicksort | |
func Sort[T constraints.Ordered](buf []T) { | |
quick(buf, 0, len(buf)-1) | |
} | |
func quick[T constraints.Ordered](a []T, l, r int) { | |
if l >= r { | |
return | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func Sort[T constraints.Ordered](buf []T) { | |
tmp := make([]T, len(buf)) | |
merge_sort[T](buf, 0, len(buf)-1, tmp) | |
} | |
func merge_sort[T constraints.Ordered](a []T, first, last int, tmp []T) { | |
if first < last { | |
middle := (first + last) / 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func Sort[T constraints.Ordered](buf []T) { | |
for i := 1; i < len(buf); i++ { | |
for j := i; j > 0; j-- { | |
if buf[j] < buf[j-1] { | |
tmp := buf[j-1] | |
buf[j-1] = buf[j] | |
buf[j] = tmp | |
} else { | |
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package query | |
func Sort[T constraints.Ordered](buf []T) { | |
for i := 0; i < len(buf)-1; i++ { | |
min := i | |
for j := i; j < len(buf); j++ { | |
if buf[min] > buf[j] { | |
min = j | |
} | |
} |
OlderNewer