classbench 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/classbench.gemspec +5 -5
- data/lib/classbench/trie.rb +92 -0
- data/lib/classbench/{tier_node.rb → trie_node.rb} +2 -2
- data/lib/classbench.rb +20 -5
- metadata +4 -4
- data/lib/classbench/tier.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0476c25d8f3928d4d671593eb0008199838443a1
|
4
|
+
data.tar.gz: af9f48ef68198ea312cf5bf2c7e7f7264df1ddee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7df7583555c764b29b9a3b2bfa496fe58f20350b22f449d83bda3a09242c4eea79b2361306a301781cd32904be09ae2de8b34ebfb9dc8c04938cb7bb5e93431a
|
7
|
+
data.tar.gz: 470d1129f07c85f2db6081a419db550cd9ff096aa5879748b2fade35e80b189424df2165b302de5f441aceb984b23ce892514d815b0edc24da1e368c987c6c7a
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/classbench.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: classbench 0.0.
|
5
|
+
# stub: classbench 0.0.5 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "classbench"
|
9
|
-
s.version = "0.0.
|
9
|
+
s.version = "0.0.5"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Adam Lucansky", "Gianni Antichi", "Jiri Matousek"]
|
14
|
-
s.date = "2015-06-
|
14
|
+
s.date = "2015-06-21"
|
15
15
|
s.description = "Statistical generation of firewall/OpenFLOW rules based on seed file (IN DEVELOPMENT)"
|
16
16
|
s.email = "adamlucansky@gmail.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -28,8 +28,8 @@ Gem::Specification.new do |s|
|
|
28
28
|
"VERSION",
|
29
29
|
"classbench.gemspec",
|
30
30
|
"lib/classbench.rb",
|
31
|
-
"lib/classbench/
|
32
|
-
"lib/classbench/
|
31
|
+
"lib/classbench/trie.rb",
|
32
|
+
"lib/classbench/trie_node.rb",
|
33
33
|
"test/helper.rb",
|
34
34
|
"test/test_classbench.rb",
|
35
35
|
"test/test_docopt.rb"
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module Classbench
|
2
|
+
|
3
|
+
# Structure representing trie statistics proposed in the ClassBench tool.
|
4
|
+
#
|
5
|
+
# Array members store statistics defined separately for each level of the
|
6
|
+
# trie. Prefix nesting is defined for the whole trie.
|
7
|
+
Struct.new("ClassbenchStats",
|
8
|
+
# (float[]) number of prefixes (not prefix nodes) with given length
|
9
|
+
:prefix_lengths,
|
10
|
+
# (float[]) probability of node with only one child (from all non-leaf nodes),
|
11
|
+
:branching_one_child,
|
12
|
+
# (float[]) probability of node with two children (from all non-leaf nodes)
|
13
|
+
:branching_two_children,
|
14
|
+
# (float[]) average relative weight ratio of lighter vs heavier subtree (nodes with two children only)
|
15
|
+
:skew,
|
16
|
+
# (int) maximum number of prefix nodes on an arbitrary path in the trie
|
17
|
+
:prefix_nesting)
|
18
|
+
|
19
|
+
|
20
|
+
# Structure representing statistics related to trie nodes.
|
21
|
+
#
|
22
|
+
# All the statistics are stored separately for each level of the trie.
|
23
|
+
Struct.new("NodeStats",
|
24
|
+
:leaf, # (int[]) number of leaf nodes
|
25
|
+
:one_child, # (int[]) number of nodes with one child only
|
26
|
+
:two_children, # (int[]) number of nodes with both children
|
27
|
+
:prefix, # (int[]) number of prefix nodes (not prefixes)
|
28
|
+
:non_prefix # (int[]) number of non-prefix nodes
|
29
|
+
)
|
30
|
+
|
31
|
+
# Structure representing statistics related to the trie.
|
32
|
+
#
|
33
|
+
# Statistics are divided into two groups:
|
34
|
+
# 1) statistics proposed in ClassBench tool and
|
35
|
+
# 2) statistics related to trie nodes.
|
36
|
+
#
|
37
|
+
Struct.new("TrieStats", :classbench_stats, :node_stats)
|
38
|
+
|
39
|
+
# Class for representation of a n-ary prefix tree - trie.
|
40
|
+
class Trie
|
41
|
+
attr_accessor :root
|
42
|
+
|
43
|
+
def initialize
|
44
|
+
end
|
45
|
+
|
46
|
+
def insert(prefix)
|
47
|
+
self.root = TrieNode.new(0) if not root
|
48
|
+
|
49
|
+
# Empty prefix
|
50
|
+
if prefix.size == 0
|
51
|
+
root.increment_prefixes
|
52
|
+
return
|
53
|
+
end
|
54
|
+
|
55
|
+
current_node = self.root
|
56
|
+
next_node = nil
|
57
|
+
|
58
|
+
# For each char
|
59
|
+
prefix.split('').each_with_index do |ch, i|
|
60
|
+
next_node = current_node.subtree[ch]
|
61
|
+
|
62
|
+
if next_node.nil?
|
63
|
+
next_node = TrieNode.new(i+1)
|
64
|
+
current_node.subtree[ch] = next_node
|
65
|
+
end
|
66
|
+
|
67
|
+
current_node = next_node
|
68
|
+
end
|
69
|
+
|
70
|
+
current_node.increment_prefixes
|
71
|
+
end
|
72
|
+
|
73
|
+
# Erase not implemented/neccessary
|
74
|
+
|
75
|
+
def get_stats
|
76
|
+
return if not root
|
77
|
+
root.compute_weights
|
78
|
+
|
79
|
+
level = root.level
|
80
|
+
|
81
|
+
que = [root]
|
82
|
+
# BFS, append from right, take from left
|
83
|
+
while not que.empty?
|
84
|
+
node = que.shift # take one from left
|
85
|
+
|
86
|
+
node.subtree.each do |char, subnode|
|
87
|
+
que << subnode
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
class
|
1
|
+
class TrieNode
|
2
2
|
attr_accessor :level # depth of node
|
3
3
|
attr_accessor :prefixes_count # number of occurences of the prefix
|
4
4
|
|
5
|
-
attr_accessor :subtree # Hash mapping character ->
|
5
|
+
attr_accessor :subtree # Hash mapping character -> TrieNode
|
6
6
|
attr_accessor :subtree_weights
|
7
7
|
|
8
8
|
def initialize(level)
|
data/lib/classbench.rb
CHANGED
@@ -1,11 +1,26 @@
|
|
1
|
-
require 'classbench/
|
2
|
-
require 'classbench/
|
1
|
+
require 'classbench/trie'
|
2
|
+
require 'classbench/trie_node'
|
3
|
+
|
4
|
+
require 'pp'
|
3
5
|
|
4
6
|
module Classbench
|
7
|
+
def self.generate_prefix
|
8
|
+
len = rand(33)
|
9
|
+
|
10
|
+
(0...len).map { [0,1][rand(2)]}.join
|
11
|
+
end
|
12
|
+
|
5
13
|
def self.hi
|
6
|
-
|
7
|
-
t
|
8
|
-
t.insert "
|
14
|
+
t = Trie.new
|
15
|
+
#2.times { t.insert "101" }
|
16
|
+
#3.times { t.insert "100" }
|
17
|
+
500_000.times { t.insert generate_prefix }
|
18
|
+
puts "Stats"
|
19
|
+
t.get_stats
|
20
|
+
|
21
|
+
puts "Done"
|
22
|
+
|
23
|
+
|
9
24
|
|
10
25
|
end
|
11
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: classbench
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Lucansky
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-06-
|
13
|
+
date: 2015-06-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rdoc
|
@@ -72,8 +72,8 @@ files:
|
|
72
72
|
- VERSION
|
73
73
|
- classbench.gemspec
|
74
74
|
- lib/classbench.rb
|
75
|
-
- lib/classbench/
|
76
|
-
- lib/classbench/
|
75
|
+
- lib/classbench/trie.rb
|
76
|
+
- lib/classbench/trie_node.rb
|
77
77
|
- test/helper.rb
|
78
78
|
- test/test_classbench.rb
|
79
79
|
- test/test_docopt.rb
|
data/lib/classbench/tier.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
module Classbench
|
2
|
-
|
3
|
-
# Class for representation of a n-ary prefix tree - trie.
|
4
|
-
class Tier
|
5
|
-
attr_accessor :root
|
6
|
-
|
7
|
-
def insert(prefix)
|
8
|
-
self.root = TierNode.new(0) if not root
|
9
|
-
|
10
|
-
# Empty prefix
|
11
|
-
if prefix.size == 0
|
12
|
-
root.increment_prefixes
|
13
|
-
return
|
14
|
-
end
|
15
|
-
|
16
|
-
current_node = self.root
|
17
|
-
next_node = nil
|
18
|
-
|
19
|
-
# For each char
|
20
|
-
prefix.split('').each_with_index do |ch, i|
|
21
|
-
next_node = current_node.subtree[ch]
|
22
|
-
|
23
|
-
if next_node.nil?
|
24
|
-
next_node = TierNode.new(i+1)
|
25
|
-
current_node.subtree[ch] = next_node
|
26
|
-
end
|
27
|
-
|
28
|
-
current_node = next_node
|
29
|
-
end
|
30
|
-
|
31
|
-
current_node.increment_prefixes
|
32
|
-
end
|
33
|
-
|
34
|
-
# Erase not implemented/neccessary
|
35
|
-
|
36
|
-
def get_stats
|
37
|
-
return if not root
|
38
|
-
|
39
|
-
root.compute_weights
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|