summaryrefslogtreecommitdiff
path: root/vendor/github.com/jackc/puddle/v2/log.go
diff options
context:
space:
mode:
authorLibravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2023-11-06 14:44:53 +0000
committerLibravatar GitHub <noreply@github.com>2023-11-06 14:44:53 +0000
commit9b76afc851090268316fd8890366957632b49a44 (patch)
tree4f1539dd8f831bb22bad9ae21d8ab1d17278b323 /vendor/github.com/jackc/puddle/v2/log.go
parent[chore]: Bump github.com/tdewolff/minify/v2 from 2.20.0 to 2.20.6 (#2337) (diff)
downloadgotosocial-9b76afc851090268316fd8890366957632b49a44.tar.xz
[chore]: Bump github.com/jackc/pgx/v5 from 5.4.3 to 5.5.0 (#2336)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/github.com/jackc/puddle/v2/log.go')
-rw-r--r--vendor/github.com/jackc/puddle/v2/log.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/vendor/github.com/jackc/puddle/v2/log.go b/vendor/github.com/jackc/puddle/v2/log.go
new file mode 100644
index 000000000..b21b94630
--- /dev/null
+++ b/vendor/github.com/jackc/puddle/v2/log.go
@@ -0,0 +1,32 @@
+package puddle
+
+import "unsafe"
+
+type ints interface {
+ int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64
+}
+
+// log2Int returns log2 of an integer. This function panics if val < 0. For val
+// == 0, returns 0.
+func log2Int[T ints](val T) uint8 {
+ if val <= 0 {
+ panic("log2 of non-positive number does not exist")
+ }
+
+ return log2IntRange(val, 0, uint8(8*unsafe.Sizeof(val)))
+}
+
+func log2IntRange[T ints](val T, begin, end uint8) uint8 {
+ length := end - begin
+ if length == 1 {
+ return begin
+ }
+
+ delim := begin + length/2
+ mask := T(1) << delim
+ if mask > val {
+ return log2IntRange(val, begin, delim)
+ } else {
+ return log2IntRange(val, delim, end)
+ }
+}