Added a counter tree experiment.
Added more logging for odd user agents.
This commit is contained in:
parent
5ba7aa74f7
commit
3fca8114f0
|
@ -0,0 +1,76 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math/bits"
|
||||||
|
"sync/atomic"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
const debug = true
|
||||||
|
|
||||||
|
type TreeCounterNode struct {
|
||||||
|
Value uint64
|
||||||
|
Zero *TreeCounterNode
|
||||||
|
One *TreeCounterNode
|
||||||
|
Parent *TreeCounterNode
|
||||||
|
}
|
||||||
|
|
||||||
|
// MEGA EXPERIMENTAL. Start from the right-most bits in the integer and move leftwards
|
||||||
|
type TreeTopicViewCounter struct {
|
||||||
|
root *TreeCounterNode
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTreeTopicViewCounter() *TreeTopicViewCounter {
|
||||||
|
return &TreeTopicViewCounter{
|
||||||
|
&TreeCounterNode{0, nil, nil, nil},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (counter *TreeTopicViewCounter) Bump(signTopicID int64) {
|
||||||
|
var topicID uint64 = uint64(signTopicID)
|
||||||
|
var zeroCount = bits.LeadingZeros64(topicID)
|
||||||
|
if debug {
|
||||||
|
fmt.Printf("topicID int64: %d\n", signTopicID)
|
||||||
|
fmt.Printf("topicID int64: %x\n", signTopicID)
|
||||||
|
fmt.Printf("topicID int64: %b\n", signTopicID)
|
||||||
|
fmt.Printf("topicID uint64: %b\n", topicID)
|
||||||
|
fmt.Printf("leading zeroes: %d\n", zeroCount)
|
||||||
|
|
||||||
|
var leadingZeroes = ""
|
||||||
|
for i := 0; i < zeroCount; i++ {
|
||||||
|
leadingZeroes += "0"
|
||||||
|
}
|
||||||
|
fmt.Printf("topicID lead uint64: %s%b\n", leadingZeroes, topicID)
|
||||||
|
|
||||||
|
fmt.Printf("---\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
var stopAt uint64 = 64 - uint64(zeroCount)
|
||||||
|
var spot uint64 = 1
|
||||||
|
var node = counter.root
|
||||||
|
for {
|
||||||
|
if debug {
|
||||||
|
fmt.Printf("spot: %d\n", spot)
|
||||||
|
fmt.Printf("topicID&spot: %d\n", topicID&spot)
|
||||||
|
}
|
||||||
|
if topicID&spot == 1 {
|
||||||
|
if node.One == nil {
|
||||||
|
atomic.CompareAndSwapPointer((*unsafe.Pointer)(unsafe.Pointer(node.One)), nil, unsafe.Pointer(&TreeCounterNode{0, nil, nil, node}))
|
||||||
|
}
|
||||||
|
node = node.One
|
||||||
|
} else {
|
||||||
|
if node.Zero == nil {
|
||||||
|
atomic.CompareAndSwapPointer((*unsafe.Pointer)(unsafe.Pointer(node.Zero)), nil, unsafe.Pointer(&TreeCounterNode{0, nil, nil, node}))
|
||||||
|
}
|
||||||
|
node = node.Zero
|
||||||
|
}
|
||||||
|
|
||||||
|
spot++
|
||||||
|
if spot >= stopAt {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
atomic.AddUint64(&node.Value, 1)
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCounter(t *testing.T) {
|
||||||
|
counter := newTreeTopicViewCounter()
|
||||||
|
counter.Bump(1)
|
||||||
|
counter.Bump(57)
|
||||||
|
counter.Bump(58)
|
||||||
|
counter.Bump(59)
|
||||||
|
counter.Bump(9)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestScope(t *testing.T) {
|
||||||
|
var outVar int
|
||||||
|
closureHolder := func() {
|
||||||
|
outVar = 2
|
||||||
|
}
|
||||||
|
closureHolder()
|
||||||
|
log.Print("outVar: ", outVar)
|
||||||
|
}
|
|
@ -380,10 +380,20 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
common.AgentViewCounter.Bump(13)
|
common.AgentViewCounter.Bump(13)
|
||||||
case ua == "":
|
case ua == "":
|
||||||
common.AgentViewCounter.Bump(14)
|
common.AgentViewCounter.Bump(14)
|
||||||
|
if common.Dev.DebugMode {
|
||||||
|
log.Print("prefix: ", prefix)
|
||||||
|
log.Print("req.URL.Path: ", req.URL.Path)
|
||||||
|
log.Print("extraData: ", extraData)
|
||||||
|
log.Print("req.Referer(): ", req.Referer())
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
common.AgentViewCounter.Bump(0)
|
common.AgentViewCounter.Bump(0)
|
||||||
if common.Dev.DebugMode {
|
if common.Dev.DebugMode {
|
||||||
log.Print("Unknown UA: ", req.UserAgent())
|
log.Print("Unknown UA: ", req.UserAgent())
|
||||||
|
log.Print("prefix: ", prefix)
|
||||||
|
log.Print("req.URL.Path: ", req.URL.Path)
|
||||||
|
log.Print("extraData: ", extraData)
|
||||||
|
log.Print("req.Referer(): ", req.Referer())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -340,10 +340,20 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
common.AgentViewCounter.Bump({{.AllAgentMap.lynx}})
|
common.AgentViewCounter.Bump({{.AllAgentMap.lynx}})
|
||||||
case ua == "":
|
case ua == "":
|
||||||
common.AgentViewCounter.Bump({{.AllAgentMap.blank}})
|
common.AgentViewCounter.Bump({{.AllAgentMap.blank}})
|
||||||
|
if common.Dev.DebugMode {
|
||||||
|
log.Print("prefix: ", prefix)
|
||||||
|
log.Print("req.URL.Path: ", req.URL.Path)
|
||||||
|
log.Print("extraData: ", extraData)
|
||||||
|
log.Print("req.Referer(): ", req.Referer())
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
common.AgentViewCounter.Bump({{.AllAgentMap.unknown}})
|
common.AgentViewCounter.Bump({{.AllAgentMap.unknown}})
|
||||||
if common.Dev.DebugMode {
|
if common.Dev.DebugMode {
|
||||||
log.Print("Unknown UA: ", req.UserAgent())
|
log.Print("Unknown UA: ", req.UserAgent())
|
||||||
|
log.Print("prefix: ", prefix)
|
||||||
|
log.Print("req.URL.Path: ", req.URL.Path)
|
||||||
|
log.Print("extraData: ", extraData)
|
||||||
|
log.Print("req.Referer(): ", req.Referer())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -319,6 +319,8 @@ h1, h3 {
|
||||||
border: 1px solid var(--header-border-color);
|
border: 1px solid var(--header-border-color);
|
||||||
border-bottom: 2px solid var(--header-border-color);
|
border-bottom: 2px solid var(--header-border-color);
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
|
padding-left: 12px;
|
||||||
|
padding-right: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes fadein {
|
@keyframes fadein {
|
||||||
|
|
Loading…
Reference in New Issue