2020-08-09 04:13:34 +02:00
|
|
|
module html
|
|
|
|
|
2020-12-09 20:08:15 +01:00
|
|
|
const (
|
|
|
|
null_element = int(0x80000000)
|
|
|
|
)
|
|
|
|
|
2020-08-09 04:13:34 +02:00
|
|
|
struct Stack {
|
|
|
|
mut:
|
2020-12-09 20:08:15 +01:00
|
|
|
elements []int
|
|
|
|
size int
|
2020-08-09 04:13:34 +02:00
|
|
|
}
|
|
|
|
|
2020-12-09 20:08:15 +01:00
|
|
|
[inline]
|
|
|
|
fn is_null(data int) bool {
|
2021-02-25 13:24:30 +01:00
|
|
|
return data == html.null_element
|
2020-08-09 04:13:34 +02:00
|
|
|
}
|
|
|
|
|
2020-12-09 20:08:15 +01:00
|
|
|
[inline]
|
2020-08-09 04:13:34 +02:00
|
|
|
fn (stack Stack) is_empty() bool {
|
|
|
|
return stack.size <= 0
|
|
|
|
}
|
|
|
|
|
|
|
|
fn (stack Stack) peek() int {
|
2021-02-25 13:24:30 +01:00
|
|
|
return if !stack.is_empty() { stack.elements[stack.size - 1] } else { html.null_element }
|
2020-08-09 04:13:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn (mut stack Stack) pop() int {
|
2021-02-25 13:24:30 +01:00
|
|
|
mut to_return := html.null_element
|
2020-08-09 04:13:34 +02:00
|
|
|
if !stack.is_empty() {
|
|
|
|
to_return = stack.elements[stack.size - 1]
|
|
|
|
stack.size--
|
|
|
|
}
|
|
|
|
return to_return
|
|
|
|
}
|
|
|
|
|
|
|
|
fn (mut stack Stack) push(item int) {
|
|
|
|
if stack.elements.len > stack.size {
|
|
|
|
stack.elements[stack.size] = item
|
|
|
|
} else {
|
|
|
|
stack.elements << item
|
|
|
|
}
|
|
|
|
stack.size++
|
|
|
|
}
|
|
|
|
|
|
|
|
struct BTree {
|
|
|
|
mut:
|
|
|
|
all_tags []Tag
|
2020-09-09 14:14:44 +02:00
|
|
|
node_pointer int
|
2020-08-09 04:13:34 +02:00
|
|
|
childrens [][]int
|
|
|
|
parents []int
|
|
|
|
}
|
|
|
|
|
|
|
|
fn (mut btree BTree) add_children(tag Tag) int {
|
|
|
|
btree.all_tags << tag
|
|
|
|
if btree.all_tags.len > 1 {
|
|
|
|
for btree.childrens.len <= btree.node_pointer {
|
|
|
|
mut temp_array := btree.childrens
|
|
|
|
temp_array << []int{}
|
|
|
|
btree.childrens = temp_array
|
|
|
|
}
|
|
|
|
btree.childrens[btree.node_pointer] << btree.all_tags.len - 1
|
|
|
|
for btree.parents.len < btree.all_tags.len {
|
|
|
|
mut temp_array := btree.parents
|
|
|
|
temp_array << 0
|
|
|
|
btree.parents = temp_array
|
|
|
|
}
|
|
|
|
btree.parents[btree.all_tags.len - 1] = btree.node_pointer
|
|
|
|
}
|
|
|
|
return btree.all_tags.len - 1
|
|
|
|
}
|
|
|
|
|
2020-12-09 20:08:15 +01:00
|
|
|
[inline]
|
2020-08-09 04:13:34 +02:00
|
|
|
fn (btree BTree) get_children() []int {
|
|
|
|
return btree.childrens[btree.node_pointer]
|
|
|
|
}
|
|
|
|
|
2020-12-09 20:08:15 +01:00
|
|
|
[inline]
|
2020-08-09 04:13:34 +02:00
|
|
|
fn (btree BTree) get_parent() int {
|
|
|
|
return btree.parents[btree.node_pointer]
|
|
|
|
}
|
|
|
|
|
2020-12-09 20:08:15 +01:00
|
|
|
[inline]
|
2020-08-09 04:13:34 +02:00
|
|
|
fn (btree BTree) get_stored() Tag {
|
|
|
|
return btree.all_tags[btree.node_pointer]
|
|
|
|
}
|
|
|
|
|
|
|
|
fn (mut btree BTree) move_pointer(to int) {
|
|
|
|
if to < btree.all_tags.len {
|
|
|
|
btree.node_pointer = to
|
|
|
|
}
|
|
|
|
}
|