-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
2,876 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package core | ||
|
||
type listNode struct { | ||
prev *listNode | ||
next *listNode | ||
value interface{} | ||
} | ||
|
||
type List struct { | ||
head *listNode | ||
tail *listNode | ||
len int | ||
} | ||
|
||
func (l List) listLength() int { | ||
return l.len | ||
} | ||
|
||
func (l List) listFirst() *listNode { | ||
return l.head | ||
} | ||
|
||
func (l List) listLast() *listNode { | ||
return l.tail | ||
} | ||
|
||
func (n listNode) listPrevNode() *listNode { | ||
return n.prev | ||
} | ||
|
||
func (n listNode) listNextNode() *listNode { | ||
return n.next | ||
} | ||
|
||
func (n listNode) listNodeValue() interface{} { | ||
return n.value | ||
} | ||
|
||
func listCreate() *List { | ||
list := new(List) | ||
list.head = nil | ||
list.tail = nil | ||
list.len = 0 | ||
return list | ||
} | ||
|
||
func (l *List) listAddNodeHead(value interface{}) *List { | ||
node := new(listNode) | ||
|
||
node.value = value | ||
if l.len == 0 { | ||
l.head = node | ||
l.tail = node | ||
node.prev = nil | ||
node.next = nil | ||
} else { | ||
node.prev = nil | ||
node.next = l.head | ||
l.head.prev = node | ||
l.head = node | ||
} | ||
l.len++ | ||
return l | ||
} | ||
|
||
func (l *List) listAddNodeTail(value interface{}) *List { | ||
node := new(listNode) | ||
|
||
node.value = value | ||
if l.len == 0 { | ||
l.head = node | ||
l.tail = node | ||
node.prev = nil | ||
node.next = nil | ||
} else { | ||
node.prev = l.tail | ||
node.next = nil | ||
l.tail.next = node | ||
l.tail = node | ||
} | ||
l.len++ | ||
return l | ||
} | ||
|
||
func (l *List) listInsertNode(oldNode *listNode, value interface{}, after int) *List { | ||
node := new(listNode) | ||
node.value = value | ||
if after > 0 { | ||
|
||
} | ||
l.len++ | ||
return l | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package core | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"syscall" | ||
) | ||
|
||
//AppendToFile 写文件 | ||
func AppendToFile(fileName string, content string) error { | ||
// 以只写的模式,打开文件 | ||
f, err := os.OpenFile(fileName, os.O_WRONLY|syscall.O_CREAT, 0644) | ||
if err != nil { | ||
log.Println("aof file open failed" + err.Error()) | ||
} else { | ||
n, _ := f.Seek(0, os.SEEK_END) | ||
_, err = f.WriteAt([]byte(content), n) | ||
} | ||
defer f.Close() | ||
return err | ||
} | ||
|
||
func ReadAof(fileName string) []string { | ||
f, err := os.Open(fileName) | ||
if err != nil { | ||
fmt.Println("aof file open failed" + err.Error()) | ||
} | ||
defer f.Close() | ||
content, err := ioutil.ReadFile(fileName) | ||
if err != nil { | ||
fmt.Println("aof file read failed" + err.Error()) | ||
} | ||
ret := bytes.Split(content, []byte{'*'}) | ||
var pros = make([]string, len(ret)-1) | ||
for k, v := range ret[1:] { | ||
v := append(v[:0], append([]byte{'*'}, v[0:]...)...) | ||
pros[k] = string(v) | ||
} | ||
return pros | ||
} |
Oops, something went wrong.