Created
February 5, 2014 02:51
-
-
Save jgrar/8816705 to your computer and use it in GitHub Desktop.
ndb line patch
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
diff --git a/ndb.go b/ndb.go | |
index 4d1f5b6..9dc3f69 100644 | |
--- a/ndb.go | |
+++ b/ndb.go | |
@@ -27,7 +27,7 @@ type Tuple struct { | |
// A NDB record, which may contain multiple tuples, | |
// and may span multiple lines in the file. | |
-type Record []Tuple | |
+type Record [][]Tuple | |
// RecordSet is a related group of records, from a single entry in ndb. | |
type RecordSet []Record | |
@@ -36,9 +36,11 @@ type RecordSet []Record | |
// Returns "" if not present. | |
func (r RecordSet) Search(attr string) string { | |
for _, rec := range r { | |
- for _, tuple := range rec { | |
- if tuple.Attr == attr { | |
- return tuple.Val | |
+ for _, line := range rec { | |
+ for _, tuple := range line { | |
+ if tuple.Attr == attr { | |
+ return tuple.Val | |
+ } | |
} | |
} | |
} | |
@@ -74,7 +76,7 @@ func Open(fname string) (*Ndb, error) { | |
// open other db files | |
if dbrec := db.Search("database", ""); dbrec != nil { | |
- for _, files := range dbrec[0] { | |
+ for _, files := range dbrec[0][0] { | |
if files.Attr == "file" { | |
if files.Val == fname { | |
if first.next == nil { | |
@@ -177,13 +179,16 @@ func (n *Ndb) Search(attr, val string) RecordSet { | |
// and check each record | |
for _, record := range db.records { | |
- // each each tuple! | |
- for _, tuple := range record { | |
- // if val is "" we don't care what it is | |
- if val == "" && tuple.Attr == attr { | |
- results = append(results, record) | |
- } else if tuple.Attr == attr && tuple.Val == val { | |
- results = append(results, record) | |
+ // each line... | |
+ for _, line := range record { | |
+ // each each tuple! | |
+ for _, tuple := range line { | |
+ // if val is "" we don't care what it is | |
+ if val == "" && tuple.Attr == attr { | |
+ results = append(results, record) | |
+ } else if tuple.Attr == attr && tuple.Val == val { | |
+ results = append(results, record) | |
+ } | |
} | |
} | |
} | |
@@ -230,7 +235,7 @@ func parserec(n *Ndb) (RecordSet, error) { | |
err = terr | |
break | |
} else { | |
- rec = append(rec, tuples...) | |
+ rec = append(rec, tuples) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment