Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
andy2046 committed Jul 4, 2020
0 parents commit d909e8f
Show file tree
Hide file tree
Showing 60 changed files with 4,757 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cover.out
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2019, (0x794E6).toString(36)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.PHONY: all help test doc

all: help

help: ## Show this help
@scripts/help.sh

test: ## Test potential bugs and race conditions
@scripts/test.sh

doc: ## Generate docs
@scripts/doc.sh
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# tik

[![Documentation](https://godoc.org/github.com/andy2046/tik?status.svg)](http://godoc.org/github.com/andy2046/tik)
[![GitHub issues](https://img.shields.io/github/issues/andy2046/tik.svg)](https://github.com/andy2046/tik/issues)
[![license](https://img.shields.io/github/license/andy2046/tik.svg)](https://github.com/andy2046/tik/LICENSE)
[![Release](https://img.shields.io/github/release/andy2046/tik.svg?label=Release)](https://github.com/andy2046/tik/releases)

----

## hierarchical timing wheel made easy

simplified version of [timeout](https://github.com/wahern/timeout) in Golang

for documentation, view the [API reference](./doc.md)
29 changes: 29 additions & 0 deletions bit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package tik

import "math/bits"

// ROTR(a, k) is a circular shift to the right of bit string a by k slots.
// ROTR is a right shift, where overflowing bits to the right are added back to the left, instead of zeros.
// ROTR(a, k) = ROTL(a, n−k)
func rotr(a uint64, k int) uint64 {
return bits.RotateLeft64(a, -k)
}

// ROTL(a, k) is a circular shift to the left of bit string a by k slots.
// ROTL is a left shift, where overflowing bits to the left are added back to the right, instead of zeros.
func rotl(a uint64, k int) uint64 {
return bits.RotateLeft64(a, k)
}

// ctz input cannot be zero.
func ctz(a uint64) int {
return bits.TrailingZeros64(a)
}

func clz(a uint64) int {
return bits.LeadingZeros64(a)
}

func fls(a uint64) int {
return 64 - clz(a)
}
Loading

0 comments on commit d909e8f

Please sign in to comment.