v0.0.1
This commit is contained in:
parent
c98a5e822c
commit
df8e8d2255
2
1.xml
2
1.xml
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<mxfile host="Electron" modified="2019-11-28T07:55:49.689Z" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/12.2.2 Chrome/78.0.3904.94 Electron/7.1.0 Safari/537.36" etag="DbiUJFiSfzca5P0bM66D" version="12.2.2" type="device" pages="2">
|
||||
<diagram a*b="12" name="os-a" id="efa7a0a1-bf9b-a30e-e6df-94a7791c09e9">
|
||||
<diagram name="os-a" id="efa7a0a1-bf9b-a30e-e6df-94a7791c09e9">
|
||||
<mxGraphModel dx="2320" dy="1460" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="826" pageHeight="1169" background="#ffffff" math="0" shadow="0">
|
||||
<root >
|
||||
<mxCell id="0"/>
|
||||
|
|
47
graph.go
47
graph.go
|
@ -5,11 +5,11 @@ import (
|
|||
"log"
|
||||
)
|
||||
|
||||
var attributeNameLaw map[rune]struct{} = make(map[rune]struct{})
|
||||
var attributeNameLaw map[rune]bool = make(map[rune]bool)
|
||||
|
||||
func init() {
|
||||
for _, c := range "abcdefghijklmnopqrstuvwsyzABCDEFGHIJKLMNOPQRSTUVWSYZ-_" {
|
||||
attributeNameLaw[c] = struct{}{}
|
||||
attributeNameLaw[c] = true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@ type Element struct {
|
|||
Attributes []*Attribute
|
||||
Source []rune
|
||||
Children []*Element
|
||||
Text []string
|
||||
}
|
||||
|
||||
type Attribute struct {
|
||||
|
@ -63,7 +64,7 @@ func SkipAttribute(source []rune, cur int) int {
|
|||
}
|
||||
|
||||
func GetAttribute(source []rune, cur int) *Range {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetAttributes(source []rune, cur int) []*Attribute {
|
||||
|
@ -90,17 +91,21 @@ LOOP_TOP:
|
|||
|
||||
for ; i < len(source); i++ {
|
||||
c = source[i]
|
||||
if _, ok := attributeNameLaw[c]; !ok {
|
||||
i = SkipAttribute(source, i)
|
||||
break
|
||||
} else {
|
||||
if _, ok := attributeNameLaw[c]; ok {
|
||||
if c == ' ' || c == '>' {
|
||||
attr.Range.End = i
|
||||
break
|
||||
}
|
||||
} else {
|
||||
i = SkipAttribute(source, i)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if attr.Range.End != 0 {
|
||||
attrs = append(attrs, attr)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -108,44 +113,54 @@ LOOP_TOP:
|
|||
return attrs
|
||||
}
|
||||
|
||||
func ParseChild(parent *Element, cur int) *Element {
|
||||
func ParseChild(parent *Element, cur int) (*Element, int) {
|
||||
|
||||
start := cur
|
||||
end := start
|
||||
|
||||
child := &Element{}
|
||||
child.Tag, cur = GetTag(parent.Source, start)
|
||||
GetAttributes(parent.Source, cur)
|
||||
child.Attributes = GetAttributes(parent.Source, cur)
|
||||
|
||||
open := 1
|
||||
for i := cur; i < len(parent.Source); i++ {
|
||||
|
||||
c := parent.Source[i]
|
||||
if c == '>' {
|
||||
if parent.Source[i-1] == '\\' {
|
||||
end = i - 1
|
||||
return child
|
||||
}
|
||||
return child, i
|
||||
} else {
|
||||
for {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return nil, cur
|
||||
}
|
||||
|
||||
func GetChildren(parent *Element) {
|
||||
func GetChildren(parent *Element) (result []*Element) {
|
||||
// GetChild
|
||||
for i := parent.Range.Start; i < parent.Range.End; i++ {
|
||||
c := parent.Source[i]
|
||||
|
||||
var child *Element
|
||||
if c == '<' {
|
||||
tag := ParseChild(parent, i)
|
||||
log.Println(tag)
|
||||
child, i = ParseChild(parent, i)
|
||||
log.Println(child)
|
||||
result = append(result, child)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func ParseXML(data []byte) *Element {
|
||||
source := []rune(string(data))
|
||||
|
||||
root := &Element{tag: nil, Source: source, Pos: Range{0, len(source)}}
|
||||
root := &Element{Tag: nil, Source: source, Range: Range{0, len(source)}}
|
||||
|
||||
return root
|
||||
}
|
||||
|
|
|
@ -4,6 +4,9 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/474420502/focus/compare"
|
||||
"github.com/474420502/focus/tree/avldup"
|
||||
)
|
||||
|
||||
func Test1(t *testing.T) {
|
||||
|
@ -17,3 +20,35 @@ func Test1(t *testing.T) {
|
|||
}
|
||||
ParseXML(data)
|
||||
}
|
||||
|
||||
func BenchmarkF1(b *testing.B) {
|
||||
var law map[rune]bool = make(map[rune]bool)
|
||||
for _, c := range "abcdefghijklmnopqrstuvwsyzABCDEFGHIJKLMNOPQRSTUVWSYZ-_" {
|
||||
law[c] = true
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for _, c := range "abcd%efghij$klmnopq#rstuvwsyz!ABCDEFGHIJ^*KLMNOPQRSTUVWSYZ-_" {
|
||||
if _, ok := law[c]; ok {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkF2(b *testing.B) {
|
||||
tree := avldup.New(compare.Rune)
|
||||
for _, c := range "abcdefghijklmnopqrstuvwsyzABCDEFGHIJKLMNOPQRSTUVWSYZ-_" {
|
||||
tree.Put(c)
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for _, c := range "abcd%efghij$klmnopq#rstuvwsyz!ABCDEFGHIJ^*KLMNOPQRSTUVWSYZ-_" {
|
||||
if _, ok := tree.Get(c); ok {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user