Best Testkube code snippet using set.TestOf
orderfilev2_test.go
Source:orderfilev2_test.go
1package orderfile322import (3 "bufio"4 "bytes"5 "encoding/binary"6 "fmt"7 "io/ioutil"8 "math/rand"9 "os"10 "runtime"11 "sort"12 "strconv"13 "strings"14 "sync"15 "testing"16 "time"17 "github.com/epowsal/orderfile32/orderfiletool"18)19func TestFillKeyEndByte(t *testing.T) {20 orderpath := "testdb/TestFillKeyEndByte"21 OrderFileClear(orderpath)22 db, _ := OpenOrderFile(orderpath, 0, 0, []byte{0})23 db.PushKey([]byte("/a/b/c"), []byte{})24 _, bfill := db.FillKey([]byte("/a"))25 if bfill {26 panic("fill key error.")27 }28 _, bfill = db.FillKey([]byte("/a/b/c"))29 if !bfill {30 panic("fill key error.")31 }32 db.Flush()33 _, bfill = db.FillKey([]byte("/a"))34 if bfill {35 panic("fill key error.")36 }37 _, bfill = db.RealFill([]byte("/a/b/c"))38 if !bfill {39 panic("fill key error.")40 }41 _, bfill = db.RealFill([]byte("/a/b/c\x00"))42 if !bfill {43 panic("fill key error.")44 }45 _, bfill = db.FillKey([]byte("/a/b/c"))46 if !bfill {47 panic("fill key error.")48 }49 _, bfill = db.FillKey([]byte("/a/b/c\x00"))50 if bfill {51 panic("fill key error.")52 }53 db.Close()54 OrderFileClear(orderpath)55}56func genlongkey() []byte {57 wordbt := make([]byte, 0)58 genlen := 1<<17 + rand.Intn(512)59 for i := 0; i < genlen; i++ {60 wordbt = append(wordbt, byte(0x41+rand.Intn(26)))61 }62 return wordbt63}64func TestLongKey(t *testing.T) {65 orderpath := "testdb/testlongkey"66 OrderFileClear(orderpath)67 seed := time.Now().Unix()68 fmt.Println("seed:", seed)69 rand.Seed(seed)70 testof, _ := OpenOrderFile(orderpath, 0, 0, []byte{0})71 dd := make(map[string]int, 0)72 for i := 0; i < 100; i++ {73 lkey := genlongkey()74 testof.RealPush(lkey)75 dd[string(lkey)] = 076 }77 for key, _ := range dd {78 _, bgetlkey := testof.RealFill([]byte(key))79 if bgetlkey == false {80 panic("error")81 }82 }83 for key, _ := range dd {84 brm := testof.RealRm([]byte(key))85 if brm == false {86 panic("error")87 }88 }89 for key, _ := range dd {90 _, bgetlkey := testof.RealFill([]byte(key))91 if bgetlkey == true {92 panic("error")93 }94 }95 testof.Close()96}97func TestRmKeyFillKey(t *testing.T) {98 orderpath := "testdb/TestRmKeyFillKey"99 OrderFileClear(orderpath)100 db, _ := OpenOrderFile(orderpath, 0, 0, []byte{0})101 db.PushKey([]byte("/a/b/c"), []byte{})102 brm := db.RmKey([]byte("/a/b/c"))103 if !brm {104 panic("RmKey error.")105 }106 _, bfill := db.FillKey([]byte("/a/b/c"))107 if bfill {108 panic("fill key error.")109 }110 db.PushKey([]byte("/a/b/c"), []byte{})111 db.Flush()112 brm = db.RmKey([]byte("/a/b/c"))113 if !brm {114 panic("RmKey error.")115 }116 _, bfill = db.FillKey([]byte("/a/b/c"))117 if bfill {118 panic("fill key error.")119 }120 db.Close()121 OrderFileClear(orderpath)122}123func TestBeforeErrorDb(t *testing.T) {124 orderpath := "testdb/TestBeforeErrorDb"125 OrderFileClear(orderpath)126 seed := time.Now().Unix()127 fmt.Println("seed:", seed)128 rand.Seed(seed)129 testof, _ := OpenOrderFile(orderpath, 0, 0, nil)130 curkey := []byte{}131 for true {132 nextkey2, bnextkey := testof.NextKey(curkey)133 if !bnextkey {134 break135 }136 fmt.Println("nextkey2:", string(nextkey2))137 curkey = nextkey2138 }139 testof.PushKey([]byte("http://sc.cri.cn/20180821/5214ce44-1b57-c896-f787-b11c24a5a790.html"), []byte{})140 testof.PushKey([]byte("http://sc.cri.cn/20180831/e452aacc-861f-24e0-9ea2-b8171463b890.html"), []byte{})141 testof.PushKey([]byte("http://sc.cri.cn/20180831/e4134430-fd3d-fa5c-ba3d-8ed2165ff671.html"), []byte{})142 testof.PushKey([]byte("http://sc.cri.cn/20180927/926bda3b-7652-9bc3-b935-a9dd965cfb8e.html"), []byte{})143 testof.PushKey([]byte("http://sc.cri.cn/20180815/45a95277-367c-3bb4-e6df-67433b894caf.html"), []byte{})144 testof.PushKey([]byte("http://sc.cri.cn/20181015/65b985fe-3c96-acec-3bbc-730ddf2c5ec8.html"), []byte{})145 testof.PushKey([]byte("http://sc.cri.cn/20181119/ea692cb9-b26b-e502-72e4-e9d47c2613f1.html"), []byte{})146 testof.PushKey([]byte("http://sc.cri.cn/20190107/fb4abf5d-8129-6be5-44f6-195d66929e8c.html"), []byte{})147 testof.PushKey([]byte("http://sc.cri.cn/20190118/44e92df2-5b1c-aa96-d19c-234ab01f252a.html"), []byte{})148 testof.PushKey([]byte("http://sc.cri.cn/20190123/eba6b60a-ecf2-57ac-c4b9-b1e66923bb72.html"), []byte{})149 testof.PushKey([]byte("http://sc.cri.cn/20190123/84b5fdba-554d-1177-157e-2d7c8d5290b4.html"), []byte{})150 testof.PushKey([]byte("http://sc.cri.cn/20190125/a0bcf08d-3b82-3bb5-c1dd-f585aea5afc6.html"), []byte{})151 testof.PushKey([]byte("http://sc.cri.cn/20190201/4e0910bd-26d1-a319-c377-3d5ab327b944.html"), []byte{})152 testof.PushKey([]byte("http://sc.cri.cn/20190202/7065dd18-f076-aa98-d033-bcaaefc15876.html"), []byte{})153 testof.PushKey([]byte("http://sc.cri.cn/20190123/84b5fdba-554d-1177-157e-2d7c8d5290b4.html"), []byte{})154 testof.PushKey([]byte("http://sc.cri.cn/20190123/84b5fdba-554d-1177-157e-2d7c8d5290b4.html"), []byte{})155 testof.PushKey([]byte("http://sc.cri.cn/20190109/f8423905-9d2c-6dd0-ed1e-f2d652272017.html"), []byte{})156 testof.PushKey([]byte("http://sc.cri.cn/20190118/324339c3-bf82-45ba-b937-c6caa7267a6b.html"), []byte{})157 testof.PushKey([]byte("http://sc.cri.cn/20190131/b90c6090-ebf9-985a-5dee-3f22c61af96a.html"), []byte{})158 testof.PushKey([]byte("http://sc.cri.cn/20190202/8065cbb2-a204-3f88-3690-f4b48460ca7e.html"), []byte{})159 testof.PushKey([]byte("http://sc.cri.cn/20181208/d30b213a-a954-e40c-c78c-876845b8a96e.html"), []byte{})160 testof.PushKey([]byte("http://sc.cri.cn/20181208/d30b213a-a954-e40c-c78c-876845b8a96e.html"), []byte{})161 testof.PushKey([]byte("http://sc.cri.cn/20190131/8fd0ad95-f7b1-366a-b153-56e85f0d2293.html"), []byte{})162 testof.PushKey([]byte("http://sc.cri.cn/20190201/8160c5bf-e5c7-9f8e-716b-6b5f3378bc06.html"), []byte{})163 testof.PushKey([]byte("http://sc.cri.cn/20190201/352c3ac1-28e1-5a03-aa07-bab22560b182.html"), []byte{})164 testof.PushKey([]byte("http://sc.cri.cn/20190202/6cdc8198-c8d7-fcd9-df8c-98fd9b9b807a.html"), []byte{})165 testof.PushKey([]byte("http://sc.cri.cn/20190202/bdfb7fea-beed-6f48-4387-2ce15748b14b.html"), []byte{})166 testof.PushKey([]byte("http://sc.cri.cn/20190202/bdfb7fea-beed-6f48-4387-2ce15748b14b.html"), []byte{})167 testof.PushKey([]byte("http://sc.cri.cn/20190202/9abceede-a248-a083-2017-8b655b9ec969.html"), []byte{})168 testof.PushKey([]byte("http://sc.cri.cn/20190202/7065dd18-f076-aa98-d033-bcaaefc15876.html"), []byte{})169 testof.PushKey([]byte("http://sc.cri.cn/20190202/6a6a7224-357d-93b5-c9cc-c71d12f567e5.html"), []byte{})170 testof.PreviousKey([]byte("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"))171 testof.Close()172 OrderFileClear(orderpath)173}174func TestOrderFilePreviousKeyUseLoad(t *testing.T) {175 orderpath := "testdb/TestOrderFilePreviousKeyUseLoad"176 OrderFileClear(orderpath)177 seed := time.Now().Unix()178 //seed = 1630847798179 fmt.Println("seed:", seed)180 rand.Seed(seed)181 endbt := []byte{0}182 testof, testofer := OpenOrderFile(orderpath, 0, 0, endbt)183 allword2 := []string{}184 allword2map := make(map[string]string, 0)185 for i := 0; i < 10000; i++ {186 word2 := genword()187 word2 = append(word2, byte(0))188 word3 := genword()189 _, be := allword2map[string(word2)]190 if !be {191 testof.PushKey(word2, word3)192 allword2 = append(allword2, string(word2))193 allword2map[string(word2)] = string(word3)194 time.Sleep(15 * time.Microsecond)195 }196 }197 testof.Flush()198 testof.Close()199 testof, testofer = OpenOrderFile(orderpath, 0, 0, nil)200 if testofer != nil {201 fmt.Println(testofer)202 panic("error")203 }204 sort.Strings(allword2)205 for key, val := range allword2map {206 nextkey, bfound := testof.PreviousKey([]byte(key))207 bfnd := false208 for ind, _ := range allword2 {209 if allword2[ind] == key {210 if ind-1 >= 0 && allword2[ind-1] != string([]byte(nextkey)[:len([]byte(allword2[ind-1]))]) {211 fmt.Println("key val", key, "val:", val, "found:", string(nextkey), bfound, " should:", allword2[ind-1], " getpart:", string([]byte(nextkey)[:len([]byte(key))]))212 panic("previous key error!")213 }214 bfnd = true215 break216 }217 }218 if bfnd == false && key != allword2[0] {219 _, bfill := testof.FillKey([]byte(key))220 if bfill == false {221 fmt.Println("key val", key, "val:", val, "found:", string(nextkey), bfound)222 panic("error")223 }224 }225 }226 testof.Close()227 OrderFileClear(orderpath)228 return229}230func TestCount1(t *testing.T) {231 orderpath := "testdb/testcount1"232 OrderFileClear(orderpath)233 seed := time.Now().Unix()234 fmt.Println("seed:", seed)235 rand.Seed(seed)236 odb, _ := OpenOrderFile(orderpath, 0, 0, nil)237 ff, _ := os.OpenFile("sitelist.txt", os.O_RDONLY, 0666)238 nrd := bufio.NewReader(ff)239 totaladd := int64(0)240 urlist := []string{}241 for true {242 line, _, le := nrd.ReadLine()243 if le != nil {244 break245 }246 line = bytes.Trim(line, "\r\n\t ")247 if totaladd == 38 {248 fmt.Println("ksdjfd")249 }250 if orderfiletool.SliceSearch(urlist, string(line), 0) != -1 {251 continue252 }253 odb.RealPush(line)254 totaladd += 1255 if odb.Count() < totaladd {256 fmt.Println(totaladd, string(line))257 panic("error")258 }259 fmt.Println(totaladd)260 urlist = append(urlist, string(line))261 }262 fmt.Println(odb.Count(), totaladd)263 if odb.Count() != totaladd {264 panic("error")265 }266 ff.Close()267 odb.Close()268 OrderFileClear(orderpath)269}270func TestCrash2(t *testing.T) {271 orderpath := "testdb/testcrash2"272 OrderFileClear(orderpath)273 var testdb *OrderFile274 testdb, _ = OpenOrderFile(orderpath, 0, 8, nil)275 testdb.RealPush([]byte("84757264test text"))276 key, bok := testdb.FillKey([]byte("84757264test text"))277 fmt.Println("FillKey", string(key), bok)278 testdb.Close()279 testdb, _ = OpenOrderFile(orderpath, 0, 0, nil)280 key, bok = testdb.FillKey([]byte("84757264test text"))281 fmt.Println("FillKey", string(key), bok)282 if string(key) != "84757264test text" {283 panic("error")284 }285 brm := testdb.RealRm([]byte("84757264"))286 if brm == false {287 panic("error")288 }289 brm = testdb.RealRm([]byte("sdjkfsdhfjk"))290 if brm == true {291 panic("error")292 }293 _, bok = testdb.FillKey([]byte("84757264"))294 if bok == true {295 panic("error")296 }297 fmt.Println("randget:")298 fmt.Println(string(testdb.RandGet()))299 testdb.Close()300 OrderFileClear(orderpath)301}302func TestBinError5(t *testing.T) {303 //allowmultiopenfortest = true304 go func() {305 //http.ListenAndServe("0.0.0.0:80", nil)306 }()307 orderpath := "testdb/binerror5"308 OrderFileClear(orderpath)309 var testdb *OrderFile310 tempcompref, tempcompreferr := os.OpenFile("_curdir.headdb_err5.log", os.O_RDONLY, 0666)311 if tempcompreferr == nil {312 endpos, _ := tempcompref.Seek(0, os.SEEK_END)313 if endpos > 0 {314 // bp := false315 // ee := []byte{}316 // bnn := false317 tempcompref.Seek(0, os.SEEK_SET)318 readfrom := int64(0)319 curi := int64(0)320 readlen := int64(0)321 databuf := make([]byte, 1<<25)322 totaodocnt := 0323 for i := int64(0); i < endpos; {324 readlen = int64(len(databuf)) - readfrom325 if i+readlen > endpos {326 readlen = endpos - i327 }328 _, readerr := tempcompref.Read(databuf[readfrom : readfrom+readlen])329 if readerr != nil {330 panic(" read newsavedata have error.")331 break332 }333 curi = int64(0)334 for true {335 totaodocnt += 1336 if totaodocnt%3000 == 0 {337 fmt.Println("op count:", totaodocnt, curi, readfrom+readlen, i)338 }339 if curi+int64(len("O"))+4 < readfrom+readlen && bytes.HasPrefix(databuf[curi:], []byte("O")) {340 oplen := int64(len("O"))341 rmkeylen := binary.BigEndian.Uint32(databuf[curi+oplen : curi+oplen+4])342 if curi+oplen+4+int64(rmkeylen) < readfrom+readlen {343 curi += oplen + 4 + int64(rmkeylen)344 testdb, _ = OpenOrderFile(orderpath, 0, 0, nil)345 testdb.SetFlushInterval(9999999999999)346 } else {347 copy(databuf, databuf[curi:])348 readfrom = readfrom + readlen - curi349 break350 }351 } else if curi+int64(len("F"))+4 < readfrom+readlen && bytes.HasPrefix(databuf[curi:], []byte("F")) {352 curi += int64(len("F"))353 curi += 4354 testdb.Flush()355 //time.Sleep(30 * time.Second)356 fmt.Println("real flush positin end")357 } else if curi+int64(len("C"))+4 < readfrom+readlen && bytes.HasPrefix(databuf[curi:], []byte("C")) {358 oplen := int64(len("C"))359 pathlen := int64(binary.BigEndian.Uint32(databuf[curi+oplen : curi+oplen+4]))360 if curi+oplen+4+pathlen < readfrom+readlen {361 curi += oplen + 4 + pathlen362 testdb.Close()363 } else {364 copy(databuf, databuf[curi:])365 readfrom = readfrom + readlen - curi366 break367 }368 } else if curi+int64(len("P"))+4 < readfrom+readlen && bytes.HasPrefix(databuf[curi:], []byte("P")) {369 oplen := int64(len("P"))370 pushkeylen := binary.BigEndian.Uint32(databuf[curi+oplen : curi+oplen+4])371 if curi+oplen+4+int64(pushkeylen) < readfrom+readlen {372 pushkey := databuf[curi+oplen+4 : curi+oplen+4+int64(pushkeylen)]373 testdb.RealPush(pushkey)374 curi += oplen + 4 + int64(pushkeylen)375 //time.Sleep(time.Second)376 } else {377 copy(databuf, databuf[curi:])378 readfrom = readfrom + readlen - curi379 break380 }381 } else if curi+int64(len("RP"))+4 < readfrom+readlen && bytes.HasPrefix(databuf[curi:], []byte("RP")) {382 oplen := int64(len("RP"))383 keylen := binary.BigEndian.Uint32(databuf[curi+oplen : curi+oplen+4])384 if curi+oplen+4+int64(keylen)+4 < readfrom+readlen {385 key := databuf[curi+oplen+4 : curi+oplen+4+int64(keylen)]386 vallen := binary.BigEndian.Uint32(databuf[curi+oplen+4+int64(keylen) : curi+oplen+4+int64(keylen)+4])387 if curi+oplen+4+int64(keylen)+4+int64(vallen) < readfrom+readlen {388 val := databuf[curi+oplen+4+int64(keylen)+4 : curi+oplen+4+int64(keylen)+4+int64(vallen)]389 // if bytes.Index([]byte{0, 0, 0, 0, 0, 159, 217, 110, 0, 0, 0, 0, 217, 248, 8, 38, 0, 23, 132, 164, 0}, append(key, val...)) != -1 {390 // bp = true391 // ee = BytesCombine(key, val)392 // }393 testdb.RealRmPush(key, val)394 // if bp && bnn == false {395 // _, bn := testdb.NextKey(ee)396 // if bn {397 // bnn = true398 // }399 // }400 // if bnn {401 // testdb.NextKey(ee)402 // }403 curi += oplen + 4 + int64(keylen) + 4 + int64(vallen)404 } else {405 copy(databuf, databuf[curi:])406 readfrom = readfrom + readlen - curi407 break408 }409 //time.Sleep(time.Second)410 } else {411 copy(databuf, databuf[curi:])412 readfrom = readfrom + readlen - curi413 break414 }415 } else if curi+int64(len("R"))+4 < readfrom+readlen && bytes.HasPrefix(databuf[curi:], []byte("R")) {416 oplen := int64(len("R"))417 rmkeylen := binary.BigEndian.Uint32(databuf[curi+oplen : curi+oplen+4])418 if curi+oplen+4+int64(rmkeylen) < readfrom+readlen {419 rmkey := databuf[curi+oplen+4 : curi+oplen+4+int64(rmkeylen)]420 testdb.RealRm(rmkey)421 curi += oplen + 4 + int64(rmkeylen)422 //time.Sleep(time.Second)423 } else {424 copy(databuf, databuf[curi:])425 readfrom = readfrom + readlen - curi426 break427 }428 } else if curi+int64(len("P"))+4 < readfrom+readlen && bytes.HasPrefix(databuf[curi:], []byte("P")) {429 oplen := int64(len("P"))430 rmkeylen := binary.BigEndian.Uint32(databuf[curi+oplen : curi+oplen+4])431 if curi+oplen+4+int64(rmkeylen) < readfrom+readlen {432 rmkey := databuf[curi+oplen+4 : curi+oplen+4+int64(rmkeylen)]433 testdb.PreviousKey(rmkey)434 curi += oplen + 4 + int64(rmkeylen)435 } else {436 copy(databuf, databuf[curi:])437 readfrom = readfrom + readlen - curi438 break439 }440 } else {441 copy(databuf, databuf[curi:])442 readfrom = readfrom + readlen - curi443 break444 }445 }446 i += readlen447 }448 }449 tempcompref.Close()450 }451 if testdb != nil {452 fmt.Println("count:", testdb.Count())453 ncurkey := []byte{}454 nextcnt := 0455 for true {456 nextkey, bnext := testdb.NextKey(ncurkey)457 if !bnext {458 break459 }460 ncurkey = nextkey461 nextcnt += 1462 }463 fmt.Println("nextcnt:", nextcnt)464 previouscnt := 0465 pcurkey := []byte("\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff")466 for true {467 prekey, bnext := testdb.PreviousKey(pcurkey)468 if !bnext {469 break470 }471 pcurkey = prekey472 previouscnt += 1473 }474 fmt.Println("previouscnt:", previouscnt)475 if nextcnt != previouscnt {476 panic("error")477 }478 testval := uint64(1407435246)479 testvalbt := make([]byte, 8)480 binary.BigEndian.PutUint64(testvalbt, testval)481 fmt.Println("fillval", testvalbt)482 fillval, bfill := testdb.RealFill(testvalbt)483 if bfill == false {484 fillval, bfill = testdb.PreviousKey(testvalbt)485 if bfill == false {486 fmt.Println("fillval, bfill", fillval, bfill, testdb.Count())487 panic("error")488 } else {489 fmt.Println("previous value", fillval, bfill)490 }491 }492 orderstart := binary.BigEndian.Uint64(fillval[:8])493 part2 := binary.BigEndian.Uint32(fillval[16 : 16+4])494 orderlen := uint64(part2 >> 7)495 if !(1407435246 >= orderstart && 1407435246 < orderstart+orderlen) {496 fmt.Println("fillval", fillval, binary.BigEndian.Uint64(fillval[:8]))497 panic("error")498 }499 testdb.Close()500 }501}502func TestCHildChainFill(t *testing.T) {503 odb2path := "testdb/CHildChainFill"504 OrderFileClear(odb2path)505 odb2, _ := OpenOrderFile(odb2path, 0, 0, nil)506 a := "aaaabbbb"507 b := "aaaabbbbccccdddd"508 c := "aaaabbbbccccddddeeeeffff"509 d := "aaaabbbbccccddddeeeeffffgggghhhh"510 e := "aaaabbbbccccddddeeeeffffgggghhhhiiiiiiii"511 f := "aaaabbbbccccddddeeeeffffgggghhhhiiiiiiiijjjjjjj"512 g := "aaaabbbbccccddddeeeeffffgggghhhhiiiiiiiijjjjjjjmmmmmmmm"513 odb2.RealPush([]byte(a))514 odb2.RealPush([]byte(b))515 odb2.RealPush([]byte(c))516 odb2.RealPush([]byte(d))517 odb2.RealPush([]byte(e))518 odb2.RealPush([]byte(f))519 odb2.RealPush([]byte(g))520 odb2.RealRm([]byte(g))521 _, bfillg := odb2.RealFill([]byte(g))522 if bfillg == true || odb2.Count() != 6 {523 fmt.Println("count:", odb2.Count(), "bfillg", bfillg)524 panic("error")525 }526 odb2.RealRm([]byte(a))527 odb2.RealRm([]byte(b))528 odb2.RealRm([]byte(c))529 odb2.RealRm([]byte(d))530 odb2.RealRm([]byte(e))531 _, bfa := odb2.RealFill([]byte(a))532 if bfa == false {533 panic("error")534 }535 _, bfb := odb2.RealFill([]byte(b))536 if bfb == false {537 panic("error")538 }539 _, bfc := odb2.RealFill([]byte(c))540 if bfc == false {541 panic("error")542 }543 _, bfd := odb2.RealFill([]byte(d))544 if bfd == false {545 panic("error")546 }547 ef, bfe := odb2.RealFill([]byte(e))548 if bfe == false {549 fmt.Println("ef", string(ef), bfe)550 panic("error")551 }552 _, bff := odb2.RealFill([]byte(f))553 if bff == false {554 panic("error")555 }556 fill, bfill := odb2.RealFill([]byte(b))557 fmt.Println(string(fill), bfill)558 if string(fill) != f {559 panic("error")560 }561 prekey, bprekey := odb2.PreviousKey([]byte("\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"))562 fmt.Println(string(prekey), bprekey)563 if string(prekey) != f {564 panic("error")565 }566 nextkey, bnext := odb2.NextKey([]byte{})567 fmt.Println(string(nextkey), bnext)568 if string(nextkey) != f {569 panic("error")570 }571 if odb2.Count() != 1 {572 fmt.Println("odb2.Count():", odb2.Count())573 panic("error")574 }575 odb2.RealRm([]byte(f))576 if odb2.Count() != 0 {577 fmt.Println("odb2.Count():", odb2.Count())578 panic("error")579 }580 odb2.Close()581 OrderFileClear(odb2path)582}583func TestFillPreError3(t *testing.T) {584 odb2path := "testdb/FillPreError1"585 OrderFileClear(odb2path)586 odb2, _ := OpenOrderFile(odb2path, 0, 0, nil)587 ff, _ := os.OpenFile("testfilpreerror3.log", os.O_RDONLY, 0666)588 ffbo := bufio.NewReader(ff)589 prestart := int64(0)590 linenum := 0591 defer func() {592 if r := recover(); r != nil {593 fmt.Println("orderseginfo", linenum)594 panic(r)595 }596 }()597 totalcnt := 0598 for true {599 line, _, linee := ffbo.ReadLine()600 if linee != nil {601 break602 }603 line = bytes.Trim(line, "\r\n\t ")604 linels := bytes.Split(line, []byte(" "))605 if len(linels) != 4 {606 fmt.Println("line ", string(line))607 panic("error")608 continue609 }610 var orderstart, orderlen, datapos, dataposlen uint64611 orderstart, _ = strconv.ParseUint(string(linels[0]), 10, 64)612 orderlen, _ = strconv.ParseUint(string(linels[0]), 10, 64)613 datapos, _ = strconv.ParseUint(string(linels[0]), 10, 64)614 dataposlen, _ = strconv.ParseUint(string(linels[0]), 10, 64)615 orderseginfo := make([]byte, 20)616 binary.BigEndian.PutUint64(orderseginfo, orderstart)617 binary.BigEndian.PutUint64(orderseginfo[8:8+8], (datapos<<11)|(orderlen>>11))618 binary.BigEndian.PutUint32(orderseginfo[16:16+4], uint32((dataposlen<<11)|(orderlen&0x7FF)))619 linenum += 1620 oldcnt := odb2.Count()621 odb2.RealPush(orderseginfo)622 if odb2.Count() == oldcnt {623 fmt.Println("line ", string(line))624 panic("error")625 }626 if int64(orderstart) < prestart {627 panic("error")628 }629 prestart = int64(orderstart)630 totalcnt += 1631 }632 if odb2.Count() != 13963 {633 fmt.Println("odb2.Count():", odb2.Count(), totalcnt)634 panic("error")635 }636 orderstart2 := uint64(167833135)637 orderstart2bt := make([]byte, 8)638 binary.BigEndian.PutUint64(orderstart2bt, orderstart2)639 fmt.Println("should", orderstart2bt)640 fmt.Println("fill should")641 fmt.Println(odb2.RealFill(orderstart2bt))642 testval := uint64(167839321)643 testvalbt := make([]byte, 8)644 binary.BigEndian.PutUint64(testvalbt, testval)645 fmt.Println("fillval", testvalbt)646 fillval, bfill := odb2.RealFill(testvalbt)647 if bfill == false {648 fillval, bfill = odb2.PreviousKey(testvalbt)649 if bfill == false {650 fmt.Println("fillval, bfill", fillval, bfill, odb2.Count())651 panic("error")652 }653 }654 if bytes.Compare(fillval[:len(orderstart2bt)], orderstart2bt) != 0 {655 fmt.Println("fillval", fillval, binary.BigEndian.Uint64(fillval[:8]))656 panic("error")657 }658 odb2.Close()659 OrderFileClear(odb2path)660}661func TestFillPreError2(t *testing.T) {662 odb2path := "testdb/FillPreError1"663 OrderFileClear(odb2path)664 odb2, _ := OpenOrderFile(odb2path, 0, 0, nil)665 ff, _ := os.OpenFile("testfilpreerror2.log", os.O_RDONLY, 0666)666 ffbo := bufio.NewReader(ff)667 prestart := int64(0)668 linenum := 0669 defer func() {670 if r := recover(); r != nil {671 fmt.Println("orderseginfo", linenum)672 panic(r)673 }674 }()675 for true {676 line, _, linee := ffbo.ReadLine()677 if linee != nil {678 break679 }680 line = bytes.Trim(line, "\r\n\t ")681 linels := bytes.Split(line, []byte(" "))682 if len(linels) != 4 {683 continue684 }685 var orderstart, orderlen, datapos, dataposlen uint64686 orderstart, _ = strconv.ParseUint(string(linels[0]), 10, 64)687 orderlen, _ = strconv.ParseUint(string(linels[0]), 10, 64)688 datapos, _ = strconv.ParseUint(string(linels[0]), 10, 64)689 dataposlen, _ = strconv.ParseUint(string(linels[0]), 10, 64)690 orderseginfo := make([]byte, 20)691 binary.BigEndian.PutUint64(orderseginfo, orderstart)692 binary.BigEndian.PutUint64(orderseginfo[8:8+8], (datapos<<11)|(orderlen>>11))693 binary.BigEndian.PutUint32(orderseginfo[16:16+4], uint32((dataposlen<<11)|(orderlen&0x7FF)))694 linenum += 1695 odb2.RealPush(orderseginfo)696 if int64(orderstart) < prestart {697 panic("error")698 }699 prestart = int64(orderstart)700 }701 if odb2.Count() != 6057 {702 fmt.Println("odb2.Count():", odb2.Count())703 panic("error")704 }705 orderstart2 := uint64(67170978)706 orderstart2bt := make([]byte, 8)707 binary.BigEndian.PutUint64(orderstart2bt, orderstart2)708 fmt.Println("should", orderstart2bt)709 testval := uint64(67180859)710 testvalbt := make([]byte, 8)711 binary.BigEndian.PutUint64(testvalbt, testval)712 fmt.Println("fillval", testvalbt)713 fillval, bfill := odb2.RealFill(testvalbt)714 if bfill == false {715 fillval, bfill = odb2.PreviousKey(testvalbt)716 if bfill == false {717 fmt.Println("fillval, bfill", fillval, bfill, odb2.Count())718 panic("error")719 }720 }721 if bytes.Compare(fillval[:len(orderstart2bt)], orderstart2bt) != 0 {722 fmt.Println("fillval", fillval, binary.BigEndian.Uint64(fillval[:8]))723 panic("error")724 }725 odb2.Close()726 OrderFileClear(odb2path)727}728func TestFillPreError(t *testing.T) {729 odb2path := "testdb/FillPreError1"730 OrderFileClear(odb2path)731 odb2, _ := OpenOrderFile(odb2path, 0, 0, nil)732 ff, _ := os.OpenFile("testfilpreerror1.log", os.O_RDONLY, 0666)733 ffbo := bufio.NewReader(ff)734 prestart := int64(-1)735 for true {736 line, _, linee := ffbo.ReadLine()737 if linee != nil {738 break739 }740 line = bytes.Trim(line, "\r\n\t ")741 linels := bytes.Split(line, []byte(" "))742 if len(linels) != 4 {743 continue744 }745 var orderstart, orderlen, datapos, dataposlen uint64746 orderstart, _ = strconv.ParseUint(string(linels[0]), 10, 64)747 orderlen, _ = strconv.ParseUint(string(linels[0]), 10, 64)748 datapos, _ = strconv.ParseUint(string(linels[0]), 10, 64)749 dataposlen, _ = strconv.ParseUint(string(linels[0]), 10, 64)750 orderseginfo := make([]byte, 20)751 binary.BigEndian.PutUint64(orderseginfo, orderstart)752 binary.BigEndian.PutUint64(orderseginfo[8:8+8], (datapos<<11)|(orderlen>>11))753 binary.BigEndian.PutUint32(orderseginfo[16:16+4], uint32((dataposlen<<11)|(orderlen&0x7FF)))754 odb2.RealPush(orderseginfo)755 if int64(orderstart) < prestart {756 panic("error")757 }758 prestart = int64(orderstart)759 }760 orderstart2 := uint64(887869754)761 orderstart2bt := make([]byte, 8)762 binary.BigEndian.PutUint64(orderstart2bt, orderstart2)763 fmt.Println("should", orderstart2bt)764 testval := uint64(887881915)765 testvalbt := make([]byte, 8)766 binary.BigEndian.PutUint64(testvalbt, testval)767 fillval, bfill := odb2.RealFill(testvalbt)768 if bfill == false {769 fillval, bfill = odb2.PreviousKey(testvalbt)770 if bfill == false {771 fmt.Println("fillval, bfill", fillval, bfill, odb2.Count())772 panic("error")773 }774 }775 orderstart := uint64(887882163)776 orderstartbt := make([]byte, 8)777 binary.BigEndian.PutUint64(orderstartbt, orderstart)778 if bytes.Compare(fillval[:len(orderstartbt)], orderstartbt) == 0 {779 panic("error")780 }781 if bytes.Compare(fillval[:len(orderstartbt)], orderstart2bt) != 0 {782 fmt.Println("fillval", fillval)783 panic("error")784 }785 odb2.Close()786 OrderFileClear(odb2path)787}788func TestLkkkkk(t *testing.T) {789 seed := time.Now().Unix()790 fmt.Println("seed:", seed)791 rand.Seed(seed)792 odb2path := "testdb/testkkkkk"793 OrderFileClear(odb2path)794 odb2, _ := OpenOrderFile(odb2path, 0, 0, nil)795 fmt.Println(odb2.RealPush([]byte{}))796 fmt.Println(odb2.Count())797 if odb2.Count() != 1 {798 panic("error")799 }800 fmt.Println(odb2.RealFill([]byte{}))801 _, bf := odb2.RealFill([]byte{})802 if bf == false {803 panic("error")804 }805 fmt.Println(odb2.RealRm([]byte{}))806 fmt.Println(odb2.Count())807 if odb2.Count() != 0 {808 panic("erro")809 }810 fmt.Println(odb2.RealFill([]byte{}))811 _, bf = odb2.RealFill([]byte{})812 if bf == true {813 panic("error")814 }815 odb2.Close()816 OrderFileClear(odb2path)817}818func TestHaveErrorList(t *testing.T) {819 seed := time.Now().Unix()820 fmt.Println("seed:", seed)821 rand.Seed(seed)822 totalcnt := int64(0)823 odb2path := "testdb/testcountout2"824 OrderFileClear(odb2path)825 odb2, _ := OpenOrderFile(odb2path, 4, 0, nil)826 odb2.SetFlushInterval(99999999999)827 li := []string{}828 li2 := &sync.Map{}829 li3 := &sync.Map{}830 li4 := &sync.Map{}831 //ff, _ := os.OpenFile("fortest_sitelist.txt", os.O_RDONLY, 0666)832 ff, _ := os.OpenFile("dictionary.txt", os.O_RDONLY, 0666)833 //ff, _ := os.OpenFile("dictionary.reverse.txt", os.O_RDONLY, 0666)834 nrd := bufio.NewReader(ff)835 emptycnt := 0836 realcnt := 0837 for true {838 line, le := nrd.ReadBytes(byte('\n'))839 if le != nil {840 break841 }842 line = bytes.Trim(line, "\r\n\t ")843 if len(line) == 0 {844 emptycnt += 1845 }846 totalcnt += 1847 oldline := BytesClone(line)848 _, bold := li2.Load(string(line))849 odb2.RealPush(line)850 filk3, errofill3 := odb2.FillKey([]byte("\"tzc"))851 if errofill3 == true && bytes.Compare(filk3, []byte("\"tzc")) == 0 {852 fmt.Println(totalcnt, "filk:", filk3, line)853 panic("unknow error.")854 }855 filk, errofill := odb2.FillKey([]byte("\""))856 if errofill == true && bytes.Compare(filk, []byte("\"")) == 0 {857 fmt.Println(totalcnt, "filk:", filk, line)858 panic("unknow error.")859 }860 filk2, errofill2 := odb2.FillKey([]byte("\"0"))861 if errofill2 == true && bytes.Compare(filk, []byte("\"0")) == 0 {862 fmt.Println(totalcnt, "filk:", filk2, line)863 panic("unknow error.")864 }865 if !bold {866 realcnt += 1867 }868 if odb2.Count() != int64(realcnt) {869 fmt.Println("totalcnt", totalcnt)870 panic("error")871 }872 if bytes.Compare(oldline, line) != 0 {873 panic("error")874 }875 li = append(li, string(line))876 li2.Store(string(line), 1)877 li3.Store(string(line), 1)878 li4.Store(string(line), 1)879 }880 odb2.Flush()881 cnt := odb2.Count()882 fmt.Println("dbcount", cnt, "realcnt", realcnt)883 if cnt != int64(realcnt) {884 panic("error")885 }886 fmt.Println("randget:")887 fmt.Println(string(odb2.RandGet()))888 morekey1 := []string{}889 var curkey []byte = nil890 cnt2 := 0891 totalcnt2 := 0892 for true {893 nextkey, bnext := odb2.NextKey(curkey)894 if !bnext {895 break896 }897 totalcnt2 += 1898 if string(nextkey) == "\"tzc" {899 fmt.Println(odb2.FillKey([]byte("\"tzc")))900 fmt.Println(totalcnt2)901 panic("error")902 }903 _, bload := li3.Load(string(nextkey))904 if bload {905 li3.Delete(string(nextkey))906 } else {907 morekey1 = append(morekey1, string(nextkey))908 }909 curkey = nextkey910 cnt2 += 1911 }912 li3.Range(func(key, val interface{}) bool {913 fmt.Println("li3 remain key", key.(string))914 if len(key.(string)) != 0 {915 panic("error")916 }917 return true918 })919 fmt.Println("emptycnt", emptycnt)920 if cnt2 != int(realcnt) {921 fmt.Println("morekey1:", len(morekey1), morekey1)922 fmt.Println("cnt error:", cnt2, int(realcnt))923 panic("error")924 }925 morekey2 := []string{}926 curkey2 := []byte("\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff")927 cnt33 := 0928 totalcnt3 := 0929 for true {930 nextkey, bnext := odb2.PreviousKey(curkey2)931 if !bnext {932 break933 }934 totalcnt3 += 1935 if string(nextkey) == "\"tzc" {936 fmt.Println(odb2.FillKey([]byte("\"tzc")))937 fmt.Println(totalcnt3)938 panic("error")939 }940 _, bload := li2.Load(string(nextkey))941 if bload {942 li2.Delete(string(nextkey))943 } else {944 morekey2 = append(morekey2, string(nextkey))945 }946 curkey2 = nextkey947 cnt33 += 1948 }949 li2.Range(func(key, val interface{}) bool {950 fmt.Println("li2 remain key", key.(string))951 panic("error")952 return true953 })954 fmt.Println("emptycnt", emptycnt)955 if cnt33 != int(realcnt) {956 fmt.Println("morekey2:", len(morekey2), morekey2)957 fmt.Println("cnt error:", cnt33, int(realcnt))958 panic("error")959 }960 for kkind, kk := range li {961 kk2 := kk962 _, bfik := odb2.FillKey([]byte(kk))963 if !bfik {964 panic("error")965 }966 odb2.RealPush([]byte(kk))967 if kk2 != kk {968 fmt.Println("kk2", kk2)969 fmt.Println("kk", kk)970 panic("error")971 }972 if odb2.Count() > int64(realcnt) {973 fmt.Println(kkind, string(kk))974 panic("error")975 }976 }977 if odb2.Count() != int64(realcnt) {978 panic("error")979 }980 li4.Range(func(key, val interface{}) bool {981 odb2.RealRm([]byte(key.(string)))982 realcnt -= 1983 if odb2.Count() != int64(realcnt) {984 panic("error")985 }986 return true987 })988 fmt.Println("4 totalcnt:", totalcnt, "dbcount", odb2.Count())989 ff.Close()990 odb2.Close()991 OrderFileClear(odb2path)992}993func TestMaxMatch(t *testing.T) {994 seed := time.Now().Unix()995 fmt.Println("seed:", seed)996 rand.Seed(seed)997 odb2path := "testdb/testmaxmatch"998 OrderFileClear(odb2path)999 odb2, _ := OpenOrderFile(odb2path, 0, 0, nil)1000 odb2.RealPush([]byte("ç§æ"))1001 odb2.RealPush([]byte("ç§å¦"))1002 odb2.RealPush([]byte("ç§æåå±"))1003 odb2.RealPush([]byte("ç§æåç"))1004 odb2.RealPush([]byte("ç§æåå±å½å®¶"))1005 odb2.RealPush([]byte("ç§æåå±å½çç¥"))1006 odb2.RealPush([]byte("ç§æåå±å½å®¶äºä¸"))1007 fmt.Println("maxmatch wordmavec:")1008 artical := []byte("ç§æåå±å½å®¶äºä¸åå»å½")1009 mavec := odb2.MaxMatch(artical)1010 fmt.Println(mavec)1011 for i := 0; i < len(mavec); i++ {1012 fmt.Println(string(artical[0 : 0+mavec[i]]))1013 }1014 odb2.Close()1015 OrderFileClear(odb2path)1016}1017func TestSpecKey1(t *testing.T) {1018 orderpath := "testdb/TestSpecKey1"1019 OrderFileClear(orderpath)1020 seed := time.Now().Unix()1021 fmt.Println("seed:", seed)1022 rand.Seed(seed)1023 var testdb *OrderFile1024 testdb, _ = OpenOrderFile(orderpath, 0, 0, nil)1025 testdb.RealPush([]byte("aabbcc"))1026 fmt.Println(testdb.FillKey([]byte("aabbc")))1027 testdb.RealPush([]byte("aabbdd"))1028 testdb.RealPush([]byte("aabb"))1029 if testdb.Count() != 3 {1030 panic("count error!")1031 }1032 curkey := []byte{}1033 for true {1034 nextkey, bok := testdb.NextKey(curkey)1035 if !bok {1036 break1037 }1038 fmt.Println(string(nextkey))1039 curkey = nextkey1040 }1041 fmt.Println("fill key")1042 _, bfillok := testdb.FillKey([]byte("aabb"))1043 if !bfillok {1044 panic("remove error.")1045 }1046 bok := testdb.RealRm([]byte("aabb"))1047 if bok == false {1048 panic("remove error!")1049 }1050 if testdb.Count() != 2 {1051 panic("count error.")1052 }1053 curkey = []byte{}1054 for true {1055 nextkey, bok := testdb.NextKey(curkey)1056 if !bok {1057 break1058 }1059 fmt.Println(string(nextkey))1060 curkey = nextkey1061 }1062 testdb.Close()1063 OrderFileClear(orderpath)1064}1065func TestDeleteToEmptyError(t *testing.T) {1066 orderpath := "testdb/DeleteToEmptyError"1067 OrderFileClear(orderpath)1068 seed := time.Now().Unix()1069 fmt.Println("seed:", seed)1070 rand.Seed(seed)1071 testdb, _ := OpenOrderFile(orderpath, 0, 0, nil)1072 testdb.RealPush([]byte("http://sc.cri.cn/20190203/88444745-9a63-e7dc-9203-6ce2eef06774.html"))1073 testdb.RealPush([]byte("http://sc.cri.cn/20190203/1756b803-2d06-8f16-ebe3-a7d277343b36.html"))1074 testdb.RealRm([]byte("http://sc.cri.cn/20190203/88444745-9a63-e7dc-9203-6ce2eef06774.html"))1075 testdb.RealRm([]byte("http://sc.cri.cn/20190203/1756b803-2d06-8f16-ebe3-a7d277343b36.html"))1076 testdb.Flush()1077 testdb.Close()1078 testdb, _ = OpenOrderFile(orderpath, 0, 0, nil)1079 testdb.PreviousKey([]byte("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"))1080 testdb.Close()1081 OrderFileClear(orderpath)1082}1083func TestNewsReopenError(t *testing.T) {1084 orderpath := "testdb/NewsReopenError"1085 OrderFileClear(orderpath)1086 seed := time.Now().Unix()1087 fmt.Println("seed:", seed)1088 rand.Seed(seed)1089 testdb, _ := OpenOrderFile(orderpath, 0, 0, nil)1090 testdb.PreviousKey([]byte("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"))1091 time.Sleep(1 * time.Second)1092 testdb.PushKey([]byte("http://sc.cri.cn/20180821/5214ce44-1b57-c896-f787-b11c24a5a790.html"), []byte{})1093 testdb.PushKey([]byte("http://sc.cri.cn/20180831/e452aacc-861f-24e0-9ea2-b8171463b890.html"), []byte{})1094 testdb.PushKey([]byte("http://sc.cri.cn/20180831/e4134430-fd3d-fa5c-ba3d-8ed2165ff671.html"), []byte{})1095 testdb.PushKey([]byte("http://sc.cri.cn/20180927/926bda3b-7652-9bc3-b935-a9dd965cfb8e.html"), []byte{})1096 testdb.PushKey([]byte("http://sc.cri.cn/20180815/45a95277-367c-3bb4-e6df-67433b894caf.html"), []byte{})1097 testdb.PushKey([]byte("http://sc.cri.cn/20181015/65b985fe-3c96-acec-3bbc-730ddf2c5ec8.html"), []byte{})1098 testdb.PushKey([]byte("http://sc.cri.cn/20181119/ea692cb9-b26b-e502-72e4-e9d47c2613f1.html"), []byte{})1099 testdb.PushKey([]byte("http://sc.cri.cn/20190107/fb4abf5d-8129-6be5-44f6-195d66929e8c.html"), []byte{})1100 testdb.PushKey([]byte("http://sc.cri.cn/20190118/44e92df2-5b1c-aa96-d19c-234ab01f252a.html"), []byte{})1101 testdb.PushKey([]byte("http://sc.cri.cn/20190123/eba6b60a-ecf2-57ac-c4b9-b1e66923bb72.html"), []byte{})1102 testdb.PushKey([]byte("http://sc.cri.cn/20190123/84b5fdba-554d-1177-157e-2d7c8d5290b4.html"), []byte{})1103 testdb.PushKey([]byte("http://sc.cri.cn/20190125/a0bcf08d-3b82-3bb5-c1dd-f585aea5afc6.html"), []byte{})1104 testdb.PushKey([]byte("http://sc.cri.cn/20190201/4e0910bd-26d1-a319-c377-3d5ab327b944.html"), []byte{})1105 testdb.PushKey([]byte("http://sc.cri.cn/20190202/7065dd18-f076-aa98-d033-bcaaefc15876.html"), []byte{})1106 testdb.PushKey([]byte("http://sc.cri.cn/20190123/84b5fdba-554d-1177-157e-2d7c8d5290b4.html"), []byte{})1107 testdb.PushKey([]byte("http://sc.cri.cn/20190123/84b5fdba-554d-1177-157e-2d7c8d5290b4.html"), []byte{})1108 testdb.PushKey([]byte("http://sc.cri.cn/20190109/f8423905-9d2c-6dd0-ed1e-f2d652272017.html"), []byte{})1109 testdb.PushKey([]byte("http://sc.cri.cn/20190118/324339c3-bf82-45ba-b937-c6caa7267a6b.html"), []byte{})1110 testdb.PushKey([]byte("http://sc.cri.cn/20190131/b90c6090-ebf9-985a-5dee-3f22c61af96a.html"), []byte{})1111 testdb.PushKey([]byte("http://sc.cri.cn/20190202/8065cbb2-a204-3f88-3690-f4b48460ca7e.html"), []byte{})1112 testdb.PushKey([]byte("http://sc.cri.cn/20190203/e0cb6421-745d-2db2-e9d5-2e99756a9a14.html"), []byte{})1113 testdb.PushKey([]byte("http://sc.cri.cn/20181208/d30b213a-a954-e40c-c78c-876845b8a96e.html"), []byte{})1114 testdb.PushKey([]byte("http://sc.cri.cn/20181208/d30b213a-a954-e40c-c78c-876845b8a96e.html"), []byte{})1115 testdb.PushKey([]byte("http://sc.cri.cn/20190131/8fd0ad95-f7b1-366a-b153-56e85f0d2293.html"), []byte{})1116 testdb.PushKey([]byte("http://sc.cri.cn/20190201/8160c5bf-e5c7-9f8e-716b-6b5f3378bc06.html"), []byte{})1117 testdb.PushKey([]byte("http://sc.cri.cn/20190201/352c3ac1-28e1-5a03-aa07-bab22560b182.html"), []byte{})1118 testdb.PushKey([]byte("http://sc.cri.cn/20190202/6cdc8198-c8d7-fcd9-df8c-98fd9b9b807a.html"), []byte{})1119 testdb.PushKey([]byte("http://sc.cri.cn/20190202/bdfb7fea-beed-6f48-4387-2ce15748b14b.html"), []byte{})1120 testdb.PushKey([]byte("http://sc.cri.cn/20190202/bdfb7fea-beed-6f48-4387-2ce15748b14b.html"), []byte{})1121 testdb.PushKey([]byte("http://sc.cri.cn/20180723/16a4e4c9-899d-b7a2-59a8-47dd37a5ba7e.html"), []byte{})1122 testdb.PushKey([]byte("http://sc.cri.cn/20180725/bf96f2c8-4a83-d107-1e93-cefee1a5c957.html"), []byte{})1123 testdb.PushKey([]byte("http://sc.cri.cn/20180808/a71dafc1-bbe6-e31d-b0c4-4ed17b0c1939.html"), []byte{})1124 testdb.PushKey([]byte("http://sc.cri.cn/20180813/8c6f4f73-ec10-c964-10ec-f35accfabce6.html"), []byte{})1125 testdb.PushKey([]byte("http://sc.cri.cn/20180815/7b60cb0b-902c-96eb-52b3-ffc33b098aab.html"), []byte{})1126 testdb.PushKey([]byte("http://sc.cri.cn/20180823/aee3a3b6-b167-4b78-677f-612cce1e1310.html"), []byte{})1127 testdb.PushKey([]byte("http://sc.cri.cn/20180824/692c3bb8-a697-fe9f-dd58-ebb3e3585843.html"), []byte{})1128 testdb.PushKey([]byte("http://sc.cri.cn/20180829/8b5cad0f-fc69-775d-53d4-8ec76c4f6429.html"), []byte{})1129 testdb.PushKey([]byte("http://sc.cri.cn/20180831/7b9e5137-2408-1c48-2a2e-159025d6c876.html"), []byte{})1130 testdb.PushKey([]byte("http://sc.cri.cn/20180831/e56ec5d8-3a8a-915e-a3f7-17a3c332ef86.html"), []byte{})1131 testdb.PushKey([]byte("http://sc.cri.cn/20180906/cedba55c-bb1f-47ed-8317-e4d93d70c78c.html"), []byte{})1132 testdb.PushKey([]byte("http://sc.cri.cn/20180912/4b367895-78b4-f168-63b7-8956ab9f7e6b.html"), []byte{})1133 testdb.PushKey([]byte("http://sc.cri.cn/20180914/7450ea0e-8f7b-1089-59c0-df09b472ad32.html"), []byte{})1134 testdb.PushKey([]byte("http://sc.cri.cn/20180917/ba2b74df-2807-9bd2-7a08-30f57be487c8.html"), []byte{})1135 testdb.PushKey([]byte("http://sc.cri.cn/20180921/8530415b-1a04-5b5a-4625-26122f7bfc98.html"), []byte{})1136 testdb.PushKey([]byte("http://sc.cri.cn/20180925/c378f146-a0a8-ad55-9c0c-d7b1651d9a4b.html"), []byte{})1137 testdb.PushKey([]byte("http://sc.cri.cn/20180926/c2c67246-115a-a6ed-4877-2c4948e39310.html"), []byte{})1138 testdb.PushKey([]byte("http://sc.cri.cn/20180928/263d78f8-8cf3-b9fb-bcbf-d514f608bc13.html"), []byte{})1139 testdb.PushKey([]byte("http://sc.cri.cn/20180930/ea6cc3e4-dc7b-f95e-717d-e989d956a6a4.html"), []byte{})1140 testdb.PushKey([]byte("http://sc.cri.cn/20181008/c7917509-7cee-1a8d-e849-fc4fa718aa27.html"), []byte{})1141 testdb.PushKey([]byte("http://sc.cri.cn/20181009/c53de50c-7fd9-f0de-a524-1b3a6d8fe981.html"), []byte{})1142 testdb.PushKey([]byte("http://sc.cri.cn/20181017/fc14d8f3-9ad8-10f0-490f-1cd7b49f630c.html"), []byte{})1143 testdb.PushKey([]byte("http://sc.cri.cn/20181019/77e2defd-ddff-1f19-2d3b-bd2693d94272.html"), []byte{})1144 testdb.PushKey([]byte("http://sc.cri.cn/20181022/1d649b47-8dbf-ca1e-39f4-d4f817187bea.html"), []byte{})1145 testdb.PushKey([]byte("http://sc.cri.cn/20181025/8396f2d2-aaf0-eece-68bb-1a3a5878f7ae.html"), []byte{})1146 testdb.PushKey([]byte("http://sc.cri.cn/20181030/3fc9a216-8435-d549-e875-58de574639cd.html"), []byte{})1147 testdb.PushKey([]byte("http://sc.cri.cn/20181031/8830805e-2266-63b8-1f55-34222ba45e13.html"), []byte{})1148 testdb.PushKey([]byte("http://sc.cri.cn/20181101/595f8b6c-923d-b561-257a-71dcab26d6ac.html"), []byte{})1149 testdb.PushKey([]byte("http://sc.cri.cn/20181105/c9b7b0f2-b939-ca9d-12ee-f399319ccf51.html"), []byte{})1150 testdb.PushKey([]byte("http://sc.cri.cn/20181107/76dcf3f0-aaa1-c81b-961c-a7d7b8d8e4b4.html"), []byte{})1151 testdb.PushKey([]byte("http://sc.cri.cn/20181112/d375d4fe-586b-51c2-504d-e8b69cd0dea4.html"), []byte{})1152 testdb.PushKey([]byte("http://sc.cri.cn/20181116/2e32a7f4-bd45-3793-44ed-c05c1b9e845c.html"), []byte{})1153 testdb.PushKey([]byte("http://sc.cri.cn/20181119/830936f9-7ff2-74d2-adc6-415f80ecb266.html"), []byte{})1154 testdb.PushKey([]byte("http://sc.cri.cn/20181129/e670d5b2-3225-d1e4-21e1-3a812565f14d.html"), []byte{})1155 testdb.PushKey([]byte("http://sc.cri.cn/20181204/ec32822f-43ad-f24d-c400-d317477a7220.html"), []byte{})1156 testdb.PushKey([]byte("http://sc.cri.cn/20181218/76169686-b905-5d09-4cfe-9b7b121d7c00.html"), []byte{})1157 testdb.PushKey([]byte("http://sc.cri.cn/20181219/56013f44-d691-3877-9a36-6a6c1db142ae.html"), []byte{})1158 testdb.PushKey([]byte("http://sc.cri.cn/20181226/ef5d4ec3-b61d-76f4-7f75-6132c1955176.html"), []byte{})1159 testdb.PushKey([]byte("http://sc.cri.cn/20190107/9d6cb5b5-9b35-5497-ecc2-cbd07985a19c.html"), []byte{})1160 testdb.PushKey([]byte("http://sc.cri.cn/20190118/43d6f471-db75-b743-4cd8-d94ad7d4fa1d.html"), []byte{})1161 testdb.PushKey([]byte("http://sc.cri.cn/20190121/6a41173d-2563-b2a8-81d1-9dfae23b3c18.html"), []byte{})1162 testdb.PushKey([]byte("http://sc.cri.cn/20190122/128a479e-549e-f806-b99c-4a5117be4859.html"), []byte{})1163 testdb.PushKey([]byte("http://sc.cri.cn/20190128/11e8dc66-5a23-b33a-1966-36761d3f9cf5.html"), []byte{})1164 testdb.PushKey([]byte("http://sc.cri.cn/20190129/330f8a52-910b-7b78-a922-e196f52e765b.html"), []byte{})1165 testdb.PushKey([]byte("http://sc.cri.cn/20190201/1dcd28be-5279-9709-2abf-de9dd5fe5de6.html"), []byte{})1166 testdb.RmKey([]byte("http://sc.cri.cn/highlights.html"))1167 time.Sleep(1 * time.Second)1168 testdb.Close()1169 time.Sleep(1 * time.Second)1170 testdb, _ = OpenOrderFile(orderpath, 0, 0, nil)1171 testdb.PreviousKey([]byte("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"))1172 time.Sleep(1 * time.Second)1173 testdb.PushKey([]byte("http://sc.cri.cn/20180821/5214ce44-1b57-c896-f787-b11c24a5a790.html"), []byte{})1174 testdb.PushKey([]byte("http://sc.cri.cn/20180831/e452aacc-861f-24e0-9ea2-b8171463b890.html"), []byte{})1175 testdb.PushKey([]byte("http://sc.cri.cn/20180831/e4134430-fd3d-fa5c-ba3d-8ed2165ff671.html"), []byte{})1176 testdb.PushKey([]byte("http://sc.cri.cn/20180927/926bda3b-7652-9bc3-b935-a9dd965cfb8e.html"), []byte{})1177 testdb.PushKey([]byte("http://sc.cri.cn/20180815/45a95277-367c-3bb4-e6df-67433b894caf.html"), []byte{})1178 testdb.PushKey([]byte("http://sc.cri.cn/20181015/65b985fe-3c96-acec-3bbc-730ddf2c5ec8.html"), []byte{})1179 testdb.PushKey([]byte("http://sc.cri.cn/20181119/ea692cb9-b26b-e502-72e4-e9d47c2613f1.html"), []byte{})1180 testdb.PushKey([]byte("http://sc.cri.cn/20190107/fb4abf5d-8129-6be5-44f6-195d66929e8c.html"), []byte{})1181 testdb.PushKey([]byte("http://sc.cri.cn/20190118/44e92df2-5b1c-aa96-d19c-234ab01f252a.html"), []byte{})1182 testdb.PushKey([]byte("http://sc.cri.cn/20190123/eba6b60a-ecf2-57ac-c4b9-b1e66923bb72.html"), []byte{})1183 testdb.PushKey([]byte("http://sc.cri.cn/20190123/84b5fdba-554d-1177-157e-2d7c8d5290b4.html"), []byte{})1184 testdb.PushKey([]byte("http://sc.cri.cn/20190125/a0bcf08d-3b82-3bb5-c1dd-f585aea5afc6.html"), []byte{})1185 testdb.PushKey([]byte("http://sc.cri.cn/20190201/4e0910bd-26d1-a319-c377-3d5ab327b944.html"), []byte{})1186 testdb.PushKey([]byte("http://sc.cri.cn/20190202/7065dd18-f076-aa98-d033-bcaaefc15876.html"), []byte{})1187 testdb.PushKey([]byte("http://sc.cri.cn/20190123/84b5fdba-554d-1177-157e-2d7c8d5290b4.html"), []byte{})1188 testdb.PushKey([]byte("http://sc.cri.cn/20190123/84b5fdba-554d-1177-157e-2d7c8d5290b4.html"), []byte{})1189 testdb.PushKey([]byte("http://sc.cri.cn/20190109/f8423905-9d2c-6dd0-ed1e-f2d652272017.html"), []byte{})1190 testdb.PushKey([]byte("http://sc.cri.cn/20190118/324339c3-bf82-45ba-b937-c6caa7267a6b.html"), []byte{})1191 testdb.PushKey([]byte("http://sc.cri.cn/20190131/b90c6090-ebf9-985a-5dee-3f22c61af96a.html"), []byte{})1192 testdb.PushKey([]byte("http://sc.cri.cn/20190202/8065cbb2-a204-3f88-3690-f4b48460ca7e.html"), []byte{})1193 testdb.PushKey([]byte("http://sc.cri.cn/20181208/d30b213a-a954-e40c-c78c-876845b8a96e.html"), []byte{})1194 testdb.PushKey([]byte("http://sc.cri.cn/20181208/d30b213a-a954-e40c-c78c-876845b8a96e.html"), []byte{})1195 testdb.PushKey([]byte("http://sc.cri.cn/20190131/8fd0ad95-f7b1-366a-b153-56e85f0d2293.html"), []byte{})1196 testdb.PushKey([]byte("http://sc.cri.cn/20190201/8160c5bf-e5c7-9f8e-716b-6b5f3378bc06.html"), []byte{})1197 testdb.PushKey([]byte("http://sc.cri.cn/20190201/352c3ac1-28e1-5a03-aa07-bab22560b182.html"), []byte{})1198 testdb.PushKey([]byte("http://sc.cri.cn/20190202/6cdc8198-c8d7-fcd9-df8c-98fd9b9b807a.html"), []byte{})1199 testdb.PushKey([]byte("http://sc.cri.cn/20190202/bdfb7fea-beed-6f48-4387-2ce15748b14b.html"), []byte{})1200 testdb.PushKey([]byte("http://sc.cri.cn/20190202/bdfb7fea-beed-6f48-4387-2ce15748b14b.html"), []byte{})1201 testdb.PushKey([]byte("http://sc.cri.cn/20190202/7065dd18-f076-aa98-d033-bcaaefc15876.html"), []byte{})1202 testdb.PushKey([]byte("http://sc.cri.cn/20190202/6a6a7224-357d-93b5-c9cc-c71d12f567e5.html"), []byte{})1203 testdb.PushKey([]byte("http://sc.cri.cn/20190203/88444745-9a63-e7dc-9203-6ce2eef06774.html"), []byte{})1204 testdb.PushKey([]byte("http://sc.cri.cn/20190203/1756b803-2d06-8f16-ebe3-a7d277343b36.html"), []byte{})1205 testdb.RmKey([]byte("http://sc.cri.cn/20190203/e0cb6421-745d-2db2-e9d5-2e99756a9a14.html"))1206 time.Sleep(1 * time.Second)1207 testdb.Close()1208 time.Sleep(1 * time.Second)1209 testdb, _ = OpenOrderFile(orderpath, 0, 0, nil)1210 testdb.PreviousKey([]byte("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"))1211 testdb.PushKey([]byte("http://sc.cri.cn/20180821/5214ce44-1b57-c896-f787-b11c24a5a790.html"), []byte{})1212 testdb.PushKey([]byte("http://sc.cri.cn/20180831/e452aacc-861f-24e0-9ea2-b8171463b890.html"), []byte{})1213 testdb.PushKey([]byte("http://sc.cri.cn/20180831/e4134430-fd3d-fa5c-ba3d-8ed2165ff671.html"), []byte{})1214 testdb.PushKey([]byte("http://sc.cri.cn/20180927/926bda3b-7652-9bc3-b935-a9dd965cfb8e.html"), []byte{})1215 testdb.PushKey([]byte("http://sc.cri.cn/20180815/45a95277-367c-3bb4-e6df-67433b894caf.html"), []byte{})1216 testdb.PushKey([]byte("http://sc.cri.cn/20181015/65b985fe-3c96-acec-3bbc-730ddf2c5ec8.html"), []byte{})1217 testdb.PushKey([]byte("http://sc.cri.cn/20181119/ea692cb9-b26b-e502-72e4-e9d47c2613f1.html"), []byte{})1218 testdb.PushKey([]byte("http://sc.cri.cn/20190107/fb4abf5d-8129-6be5-44f6-195d66929e8c.html"), []byte{})1219 testdb.PushKey([]byte("http://sc.cri.cn/20190118/44e92df2-5b1c-aa96-d19c-234ab01f252a.html"), []byte{})1220 testdb.PushKey([]byte("http://sc.cri.cn/20190123/eba6b60a-ecf2-57ac-c4b9-b1e66923bb72.html"), []byte{})1221 testdb.PushKey([]byte("http://sc.cri.cn/20190123/84b5fdba-554d-1177-157e-2d7c8d5290b4.html"), []byte{})1222 testdb.PushKey([]byte("http://sc.cri.cn/20190125/a0bcf08d-3b82-3bb5-c1dd-f585aea5afc6.html"), []byte{})1223 testdb.PushKey([]byte("http://sc.cri.cn/20190201/4e0910bd-26d1-a319-c377-3d5ab327b944.html"), []byte{})1224 testdb.PushKey([]byte("http://sc.cri.cn/20190202/7065dd18-f076-aa98-d033-bcaaefc15876.html"), []byte{})1225 testdb.PushKey([]byte("http://sc.cri.cn/20190123/84b5fdba-554d-1177-157e-2d7c8d5290b4.html"), []byte{})1226 testdb.PushKey([]byte("http://sc.cri.cn/20190123/84b5fdba-554d-1177-157e-2d7c8d5290b4.html"), []byte{})1227 testdb.PushKey([]byte("http://sc.cri.cn/20190109/f8423905-9d2c-6dd0-ed1e-f2d652272017.html"), []byte{})1228 testdb.PushKey([]byte("http://sc.cri.cn/20190118/324339c3-bf82-45ba-b937-c6caa7267a6b.html"), []byte{})1229 testdb.PushKey([]byte("http://sc.cri.cn/20190131/b90c6090-ebf9-985a-5dee-3f22c61af96a.html"), []byte{})1230 testdb.PushKey([]byte("http://sc.cri.cn/20190202/8065cbb2-a204-3f88-3690-f4b48460ca7e.html"), []byte{})1231 testdb.PushKey([]byte("http://sc.cri.cn/20181208/d30b213a-a954-e40c-c78c-876845b8a96e.html"), []byte{})1232 testdb.PushKey([]byte("http://sc.cri.cn/20181208/d30b213a-a954-e40c-c78c-876845b8a96e.html"), []byte{})1233 testdb.PushKey([]byte("http://sc.cri.cn/20190131/8fd0ad95-f7b1-366a-b153-56e85f0d2293.html"), []byte{})1234 testdb.PushKey([]byte("http://sc.cri.cn/20190201/8160c5bf-e5c7-9f8e-716b-6b5f3378bc06.html"), []byte{})1235 testdb.PushKey([]byte("http://sc.cri.cn/20190201/352c3ac1-28e1-5a03-aa07-bab22560b182.html"), []byte{})1236 testdb.PushKey([]byte("http://sc.cri.cn/20190202/6cdc8198-c8d7-fcd9-df8c-98fd9b9b807a.html"), []byte{})1237 testdb.PushKey([]byte("http://sc.cri.cn/20190202/bdfb7fea-beed-6f48-4387-2ce15748b14b.html"), []byte{})1238 testdb.PushKey([]byte("http://sc.cri.cn/20190202/bdfb7fea-beed-6f48-4387-2ce15748b14b.html"), []byte{})1239 testdb.PushKey([]byte("http://sc.cri.cn/20190202/6cdc8198-c8d7-fcd9-df8c-98fd9b9b807a.html"), []byte{})1240 testdb.PushKey([]byte("http://sc.cri.cn/20190202/9abceede-a248-a083-2017-8b655b9ec969.html"), []byte{})1241 testdb.PushKey([]byte("http://sc.cri.cn/20190202/7065dd18-f076-aa98-d033-bcaaefc15876.html"), []byte{})1242 testdb.PushKey([]byte("http://sc.cri.cn/20190202/6a6a7224-357d-93b5-c9cc-c71d12f567e5.html"), []byte{})1243 time.Sleep(1 * time.Second)1244 testdb.RmKey([]byte("http://sc.cri.cn/20190203/88444745-9a63-e7dc-9203-6ce2eef06774.html"))1245 time.Sleep(1 * time.Second)1246 testdb.Close()1247 time.Sleep(1 * time.Second)1248 testdb, _ = OpenOrderFile(orderpath, 0, 0, nil)1249 testdb.PreviousKey([]byte("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"))1250 testdb.PushKey([]byte("http://sc.cri.cn/20180821/5214ce44-1b57-c896-f787-b11c24a5a790.html"), []byte{})1251 testdb.PushKey([]byte("http://sc.cri.cn/20180831/e452aacc-861f-24e0-9ea2-b8171463b890.html"), []byte{})1252 testdb.PushKey([]byte("http://sc.cri.cn/20180831/e4134430-fd3d-fa5c-ba3d-8ed2165ff671.html"), []byte{})1253 testdb.PushKey([]byte("http://sc.cri.cn/20180927/926bda3b-7652-9bc3-b935-a9dd965cfb8e.html"), []byte{})1254 testdb.PushKey([]byte("http://sc.cri.cn/20180815/45a95277-367c-3bb4-e6df-67433b894caf.html"), []byte{})1255 testdb.PushKey([]byte("http://sc.cri.cn/20181015/65b985fe-3c96-acec-3bbc-730ddf2c5ec8.html"), []byte{})1256 testdb.PushKey([]byte("http://sc.cri.cn/20181119/ea692cb9-b26b-e502-72e4-e9d47c2613f1.html"), []byte{})1257 testdb.PushKey([]byte("http://sc.cri.cn/20190107/fb4abf5d-8129-6be5-44f6-195d66929e8c.html"), []byte{})1258 testdb.PushKey([]byte("http://sc.cri.cn/20190118/44e92df2-5b1c-aa96-d19c-234ab01f252a.html"), []byte{})1259 testdb.PushKey([]byte("http://sc.cri.cn/20190123/eba6b60a-ecf2-57ac-c4b9-b1e66923bb72.html"), []byte{})1260 testdb.PushKey([]byte("http://sc.cri.cn/20190123/84b5fdba-554d-1177-157e-2d7c8d5290b4.html"), []byte{})1261 testdb.PushKey([]byte("http://sc.cri.cn/20190125/a0bcf08d-3b82-3bb5-c1dd-f585aea5afc6.html"), []byte{})1262 testdb.PushKey([]byte("http://sc.cri.cn/20190201/4e0910bd-26d1-a319-c377-3d5ab327b944.html"), []byte{})1263 testdb.PushKey([]byte("http://sc.cri.cn/20190202/7065dd18-f076-aa98-d033-bcaaefc15876.html"), []byte{})1264 testdb.PushKey([]byte("http://sc.cri.cn/20190123/84b5fdba-554d-1177-157e-2d7c8d5290b4.html"), []byte{})1265 testdb.PushKey([]byte("http://sc.cri.cn/20190123/84b5fdba-554d-1177-157e-2d7c8d5290b4.html"), []byte{})1266 testdb.PushKey([]byte("http://sc.cri.cn/20190109/f8423905-9d2c-6dd0-ed1e-f2d652272017.html"), []byte{})1267 testdb.PushKey([]byte("http://sc.cri.cn/20190118/324339c3-bf82-45ba-b937-c6caa7267a6b.html"), []byte{})1268 testdb.PushKey([]byte("http://sc.cri.cn/20190131/b90c6090-ebf9-985a-5dee-3f22c61af96a.html"), []byte{})1269 testdb.PushKey([]byte("http://sc.cri.cn/20190202/8065cbb2-a204-3f88-3690-f4b48460ca7e.html"), []byte{})1270 testdb.PushKey([]byte("http://sc.cri.cn/20181208/d30b213a-a954-e40c-c78c-876845b8a96e.html"), []byte{})1271 testdb.PushKey([]byte("http://sc.cri.cn/20181208/d30b213a-a954-e40c-c78c-876845b8a96e.html"), []byte{})1272 testdb.PushKey([]byte("http://sc.cri.cn/20190131/8fd0ad95-f7b1-366a-b153-56e85f0d2293.html"), []byte{})1273 testdb.PushKey([]byte("http://sc.cri.cn/20190201/8160c5bf-e5c7-9f8e-716b-6b5f3378bc06.html"), []byte{})1274 testdb.PushKey([]byte("http://sc.cri.cn/20190201/352c3ac1-28e1-5a03-aa07-bab22560b182.html"), []byte{})1275 testdb.PushKey([]byte("http://sc.cri.cn/20190202/6cdc8198-c8d7-fcd9-df8c-98fd9b9b807a.html"), []byte{})1276 testdb.PushKey([]byte("http://sc.cri.cn/20190202/bdfb7fea-beed-6f48-4387-2ce15748b14b.html"), []byte{})1277 testdb.PushKey([]byte("http://sc.cri.cn/20190202/bdfb7fea-beed-6f48-4387-2ce15748b14b.html"), []byte{})1278 testdb.PushKey([]byte("http://sc.cri.cn/20190202/9abceede-a248-a083-2017-8b655b9ec969.html"), []byte{})1279 testdb.PushKey([]byte("http://sc.cri.cn/20190202/7065dd18-f076-aa98-d033-bcaaefc15876.html"), []byte{})1280 testdb.PushKey([]byte("http://sc.cri.cn/20190202/6a6a7224-357d-93b5-c9cc-c71d12f567e5.html"), []byte{})1281 testdb.RmKey([]byte("http://sc.cri.cn/20190203/1756b803-2d06-8f16-ebe3-a7d277343b36.html"))1282 time.Sleep(1 * time.Second)1283 testdb.Close()1284 time.Sleep(1 * time.Second)1285 testdb, _ = OpenOrderFile(orderpath, 0, 0, nil)1286 testdb.PreviousKey([]byte("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"))1287 testdb.Close()1288 OrderFileClear(orderpath)1289}1290func TestOrderFileNextKey(t *testing.T) {1291 orderpath := "testdb/TestOrderFileNextKey"1292 OrderFileClear(orderpath)1293 seed := time.Now().Unix()1294 fmt.Println("seed:", seed)1295 rand.Seed(seed)1296 endbt := []byte{0}1297 testof, _ := OpenOrderFile(orderpath, 0, 0, endbt)1298 allword2 := []string{}1299 allword2map := make(map[string]string, 0)1300 //nextkeytestf, _ := os.Create("nextkeytest.txt")1301 for i := 0; i < 10000; i++ {1302 word2 := genword()1303 word2 = append(word2, byte(0))1304 word3 := genword()1305 //word2 := genfloat32bt()1306 _, be := allword2map[string(word2)]1307 if !be {1308 testof.PushKey(word2, word3)1309 fillkey, bfillok := testof.FillKey(word2)1310 if string(fillkey) != string(word2)+string("\x00")+string(word3) {1311 fmt.Println("error ", string(word2), "word3ï¼", string(word3), "fillkey", string(fillkey), bfillok)1312 panic("error")1313 }1314 //fmt.Println(string(word2))1315 allword2 = append(allword2, string(word2))1316 //nextkeytestf.Write(word2)1317 //nextkeytestf.Write([]byte("\n"))1318 allword2map[string(word2)] = string(word3)1319 time.Sleep(15 * time.Microsecond)1320 }1321 }1322 testof.WaitBufMapEmpty()1323 //nextkeytestf.Close()1324 fmt.Println("next totalcnt:", len(allword2map))1325 sort.Strings(allword2)1326 if len(allword2) < 100 {1327 fmt.Println("allword2:", allword2)1328 }1329 nextkey2, _ := testof.NextKey([]byte(""))1330 fmt.Println("nextkey2:", string(nextkey2))1331 for key, val := range allword2map {1332 //fmt.Println("next key :", key)1333 nextkey, bfound := testof.NextKey([]byte(key))1334 if bfound == false || key+val != string(nextkey) {1335 _, bfill := testof.FillKey([]byte(key))1336 if bfill == false {1337 fillkey, bfound2 := testof.FillKey([]byte(key))1338 fillkey2, bfound3 := testof.FillKey([]byte(key + val))1339 fmt.Println("key val", key, val, "found nextkey:", string(nextkey), "fillkey:", string(fillkey), bfound2, string(fillkey2), bfound3)1340 panic("next key error!")1341 }1342 }1343 }1344 testof.Close()1345 OrderFileClear(orderpath)1346}1347func TestOrderFilePreviousKey(t *testing.T) {1348 orderpath := "testdb/TestOrderFilePreviousKey"1349 OrderFileClear(orderpath)1350 seed := time.Now().Unix()1351 fmt.Println("seed:", seed)1352 //seed = 15546974381353 rand.Seed(seed)1354 testof, _ := OpenOrderFile(orderpath, 0, 0, nil)1355 allword2 := []string{}1356 allword2map := make(map[string]string, 0)1357 //nextkeytestf, _ := os.Create("previouskeytest.txt")1358 for i := 0; i < 10000; i++ {1359 word2 := genword()1360 word2 = append(word2, byte(0))1361 word3 := genword()1362 _, be := allword2map[string(word2)]1363 if !be {1364 testof.PushKey(word2, word3)1365 //fmt.Println(string(word2))1366 allword2 = append(allword2, string(word2))1367 //nextkeytestf.Write(word2)1368 //nextkeytestf.Write([]byte("\n"))1369 //nextkeytestf.Sync()1370 allword2map[string(word2)] = string(word3)1371 time.Sleep(15 * time.Microsecond)1372 }1373 }1374 testof.WaitBufMapEmpty()1375 testof.Close()1376 sort.Strings(allword2)1377 testof, _ = OpenOrderFile(orderpath, 0, 0, nil)1378 for key, val := range allword2map {1379 //fmt.Println("find previous for :", allword2[i])1380 nextkey, bfound := testof.PreviousKey([]byte(key))1381 bfnd := false1382 for ind, _ := range allword2 {1383 if ind > 0 && allword2[ind] == key {1384 if allword2[ind-1] != string([]byte(nextkey)[:len([]byte(allword2[ind-1]))]) {1385 fmt.Println("key val", key, "val:", val, "found:", string(nextkey), bfound, " should:", allword2[ind-1], " getpart:", string([]byte(nextkey)[:len([]byte(key))]))1386 panic("previous key error!")1387 }1388 bfnd = true1389 break1390 }1391 }1392 if bfnd == false && key != allword2[0] {1393 _, bfill := testof.FillKey([]byte(key))1394 if bfill == false {1395 fmt.Println("key val", key, "val:", val, "found:", string(nextkey), bfound)1396 panic("error")1397 }1398 }1399 }1400 testof.Close()1401 OrderFileClear(orderpath)1402}1403func TestOrderFile18(t *testing.T) {1404 orderpath := "testdb/TestOrderFile18"1405 OrderFileClear(orderpath)1406 OrderFileClear(orderpath + ".compress")1407 seed := time.Now().Unix()1408 //seed = 15490964591409 //seed = 15491089131410 //seed = 15491091801411 //seed = 15491101511412 //seed = 15531923861413 //seed = 15557580091414 //seed = 16308449801415 fmt.Println("seed:", seed)1416 rand.Seed(seed)1417 testof, _ := OpenOrderFile(orderpath, 0, 0, []byte{0})1418 allword3 := make(map[string]string, 0)1419 //msec := time.Duration(50)1420 for i := 0; i < 10000; i++ {1421 word := genword() //genwordlarge()1422 word2 := genword()1423 _, isword := allword3[string(word2)]1424 if !isword {1425 testof.PushKey(word2, word)1426 allword3[string(word2)] = string(word)1427 // time.Sleep(msec * time.Microsecond)1428 // msec -= 51429 }1430 }1431 // of, _ := os.OpenFile("orderfile_rare_error_fill_no_found_wordset1.txt", os.O_RDWR, 0666)1432 // rd := bufio.NewReader(of)1433 // for true {1434 // str, err := rd.ReadString('\n')1435 // if err != nil {1436 // break1437 // }1438 // strls := strings.Split(str, " ")1439 // key := append([]byte(strls[0]), byte(0))1440 // testof.PushKey(key, []byte(strls[1]))1441 // allword3[string(key)] = string(strls[1])1442 // time.Sleep(20 * time.Microsecond)1443 // }1444 testof.Close()1445 fmt.Println("Init count:", len(allword3))1446 DBCompress(orderpath, false, 10)1447 testof, _ = OpenOrderFile(orderpath+".compress", 0, 0, []byte{0})1448 for word3, word2 := range allword3 {1449 //fmt.Println(string(word3))1450 fullword, _ := testof.FillKey([]byte(word3))1451 if string(fullword) != word3+string("\x00")+word2 {1452 fmt.Println("out all")1453 fmt.Println("FillKey:", string(fullword))1454 fmt.Println("FillKey byte:", fullword)1455 fmt.Println("Right Key:", word3+string("\x00")+word2)1456 fmt.Println("Right Key byte:", []byte(word3+string("\x00")+word2))1457 curkey := ""1458 curkeycnt := 01459 for true {1460 fullword, bgetcurkey := testof.NextKey([]byte(curkey))1461 if bgetcurkey {1462 //fmt.Println("fullword:", string(fullword))1463 curkeycnt += 11464 curkey = string(fullword)1465 } else {1466 break1467 }1468 }1469 fmt.Println("total out:", curkeycnt, len(allword3))1470 fmt.Println("error", word3+word2)1471 panic("error")1472 }1473 }1474 testof.Close()1475 OrderFileClear(orderpath)1476 OrderFileClear(orderpath + ".compress")1477}1478func TestOrderFile19(t *testing.T) {1479 orderpath := "testdb/TestOrderFile19"1480 OrderFileClear(orderpath)1481 OrderFileClear(orderpath + ".new")1482 seed := time.Now().Unix()1483 //seed = 15490964591484 //seed = 15491089131485 //seed = 15491091801486 //seed = 15491101511487 //seed = 15504121261488 //seed = 15547019501489 fmt.Println("seed:", seed)1490 rand.Seed(seed)1491 fmt.Println("start neworder push")1492 allword2 := make(map[string]string, 0)1493 testof, _ := OpenOrderFile(orderpath+".new", 0, 0, nil)1494 wordset2 := []string{}1495 msec := time.Duration(50)1496 for i := 0; i < 10000; i++ {1497 word := genwordlarge()1498 word2 := genword()1499 word2 = append(word2, byte(0))1500 _, isword := allword2[string(word2)]1501 if !isword {1502 wordset2 = append(wordset2, string(word2[:len(word2)-1])+" "+string(word))1503 //bigwordtestf.Write([]byte(string(word2) + "\t" + string(word)))1504 //bigwordtestf.Write([]byte("\n"))1505 //bigwordtestf.Sync()1506 testof.PushKey(word2, word)1507 allword2[string(word2)] = string(word)1508 //fmt.Println("testget")1509 time.Sleep(msec * time.Millisecond)1510 msec -= 51511 }1512 }1513 // of2, _ := os.OpenFile("orderfile_rare_error_fill_no_found_wordset1.txt", os.O_RDWR, 0666)1514 // rd2 := bufio.NewReader(of2)1515 // for true {1516 // str, err := rd2.ReadString('\n')1517 // if err != nil {1518 // break1519 // }1520 // strls := strings.Split(str, " ")1521 // key := append([]byte(strls[0]), byte(0))1522 // testof.PushKey(key, []byte(strls[1]))1523 // allword2[string(key)] = string(strls[1])1524 // //fmt.Println("testget")1525 // time.Sleep(15 * time.Microsecond)1526 // }1527 testof.Close()1528 fmt.Println("end2")1529 testof, _ = OpenOrderFile(orderpath+".new", 0, 0, nil)1530 for word3, word2 := range allword2 {1531 fullword, fillkeyok := testof.FillKey([]byte(word3))1532 if string(fullword) != word3+word2 {1533 time.Sleep(1 * time.Second)1534 fullword2, fillkeyok2 := testof.FillKey([]byte(word3))1535 nextkey2, nextkey2ok := testof.NextKey([]byte(word3))1536 fmt.Println("error", word3+word2)1537 fmt.Println(string(fullword), "fillkeyok", fillkeyok)1538 fmt.Println("fullword2, fillkeyok2", string(fullword2), fillkeyok2)1539 fmt.Println("nextkey2, nextkey2ok", string(nextkey2), nextkey2ok)1540 word2f, _ := os.Create("wordset2.txt")1541 for _, word := range wordset2 {1542 word2f.Write([]byte(word))1543 word2f.Write([]byte("\n"))1544 }1545 word2f.Close()1546 fmt.Println(runtime.Caller(0))1547 panic("error")1548 }1549 }1550 testof.Close()1551 //3 time reload check1552 fmt.Println("3 time reload check")1553 testof, _ = OpenOrderFile(orderpath+".new", 0, 0, nil)1554 for i := 0; i < 10000; i++ {1555 word := genwordlarge()1556 word2 := genword()1557 word2 = append(word2, byte(0))1558 _, isword := allword2[string(word2)]1559 if !isword {1560 //bigwordtestf.Write([]byte(string(word2) + "\t" + string(word)))1561 //bigwordtestf.Write([]byte("\n"))1562 //bigwordtestf.Sync()1563 //fmt.Println("word1:", word, string(word))1564 //fmt.Println("word2:", word2, string(word2))1565 //fmt.Println(string(word2))1566 testof.PushKey(word2, word)1567 allword2[string(word2)] = string(word)1568 time.Sleep(15 * time.Microsecond)1569 }1570 }1571 fmt.Println("orderfile 3time fillkey")1572 for word3, word2 := range allword2 {1573 fullword, _ := testof.FillKey([]byte(word3))1574 if string(fullword) != word3+word2 {1575 fmt.Println("error", word3+word2)1576 fmt.Println("found:", string(fullword))1577 fmt.Println(runtime.Caller(0))1578 panic("error")1579 }1580 }1581 dbcount := testof.Count()1582 fmt.Println("dbcount:", dbcount)1583 testof.Close()1584 OrderFileClear(orderpath)1585 OrderFileClear(orderpath + ".new")1586}1587func TestHoldZeroLengthValue(t *testing.T) {1588 orderpath := "testdb/TestHoldZeroLengthValue"1589 OrderFileClear(orderpath)1590 seed := time.Now().Unix()1591 fmt.Println("seed:", seed)1592 rand.Seed(seed)1593 testof, _ := OpenOrderFile(orderpath, 0, 0, nil)1594 //testof.PushKey([]byte(""))1595 testof.PushKey([]byte("iodsifj"), []byte{})1596 testof.PushKey([]byte("ioiodfmfm"), []byte{})1597 testof.PushKey([]byte("dkljksdfljsg"), []byte{})1598 testof.PushKey([]byte(""), []byte{})1599 testof.PushKey([]byte("dsdklfjd"), []byte{})1600 testof.PushKey([]byte("dkiiodfj"), []byte{})1601 result, bresult := testof.FillKey([]byte(""))1602 fmt.Println("result", result, bresult)1603 curkey := []byte{0xff, 0xff, 0xff, 0xff}1604 for true {1605 prekey, bprekey := testof.PreviousKey(curkey)1606 if !bprekey {1607 break1608 }1609 fmt.Println(string(prekey), bprekey)1610 curkey = prekey1611 }1612 testof.Close()1613 OrderFileClear(orderpath)1614}1615func TestOrderFileKKK3NextError(t *testing.T) {1616 orderpath := "testdb/TestOrderFileKKK3NextError"1617 OrderFileClear(orderpath)1618 seed := time.Now().Unix()1619 fmt.Println("seed:", seed)1620 rand.Seed(seed)1621 testof4, _ := OpenOrderFile(orderpath, 0, 0, nil)1622 //prekey := []byte("")1623 prekey := []byte("kkk3_") //will get error next key1624 for true {1625 prekey, _ = testof4.NextKey(prekey)1626 if len(prekey) == 0 {1627 break1628 }1629 fmt.Println(string(prekey[:bytes.Index(prekey, []byte{0})]), prekey)1630 if "kkk3_0450954" != string(prekey[:bytes.Index(prekey, []byte{0})]) {1631 panic("error!")1632 }1633 break1634 }1635 prekey = []byte("op0zsdc")1636 for true {1637 prekey, _ = testof4.PreviousKey(prekey)1638 if len(prekey) == 0 {1639 break1640 }1641 fmt.Println(string(prekey[:bytes.Index(prekey, []byte{0})]), prekey)1642 if "kkk_vallist" != string(prekey[:bytes.Index(prekey, []byte{0})]) {1643 panic("error!")1644 }1645 break1646 }1647 prekey = []byte("wwww")1648 for true {1649 prekey, _ = testof4.PreviousKey(prekey)1650 if len(prekey) == 0 {1651 break1652 }1653 fmt.Println(string(prekey[:bytes.Index(prekey, []byte{0})]), prekey)1654 if "wwksif_vallist" != string(prekey[:bytes.Index(prekey, []byte{0})]) {1655 panic("error!")1656 }1657 break1658 }1659 prekey = []byte("kkk_dsafds")1660 for true {1661 prekey, _ = testof4.PreviousKey(prekey)1662 if len(prekey) == 0 {1663 break1664 }1665 fmt.Println(string(prekey[:bytes.Index(prekey, []byte{0})]), prekey)1666 if "kkk4_vallist" != string(prekey[:bytes.Index(prekey, []byte{0})]) {1667 panic("error!")1668 }1669 break1670 }1671 testof4.Close()1672 OrderFileClear(orderpath)1673}1674func TestOrderFileNextKeytestsample6(t *testing.T) {1675 orderpath := "testdb/TestOrderFileNextKeytestsample6"1676 OrderFileClear(orderpath)1677 seed := time.Now().Unix()1678 fmt.Println("seed:", seed)1679 rand.Seed(seed)1680 endbt := []byte{0}1681 //endbt := []byte{}1682 testof2, _ := OpenOrderFile(orderpath, 0, 0, endbt)1683 allword3 := []string{}1684 bigword, _ := ioutil.ReadFile("testsample6.txt")1685 lines := strings.Split(string(bigword), "\n")1686 for i := 0; i < len(lines); i++ {1687 if lines[i] == "" {1688 continue1689 }1690 testof2.PushKey([]byte(lines[i]), []byte{})1691 allword3 = append(allword3, string(lines[i]))1692 }1693 testof2.WaitBufMapEmpty()1694 testof2.Flush()1695 // testof2.markrmpushmap.Range(func(key, val interface{}) bool {1696 // fmt.Println(key, val)1697 // return true1698 // })1699 sort.Strings(allword3)1700 fmt.Println(allword3)1701 for i := 0; i < len(allword3); i++ {1702 fmt.Println("find next key for:", allword3[i])1703 nextkey, bfound := testof2.NextKey(append([]byte(allword3[i]), endbt...))1704 if i < len(allword3)-1 {1705 if bfound == false || allword3[i+1]+string(endbt) != string(nextkey) {1706 // testof2.markrmpushmap.Range(func(key, val interface{}) bool {1707 // fmt.Println(key, val)1708 // return true1709 // })1710 fmt.Println("i", i, "currentkey:", allword3[i], "found nextkey:", string(nextkey), "right nextkey:", allword3[i+1])1711 fmt.Println("found nextkey byte:", "found nextkey:", nextkey)1712 fmt.Println("right nextkey byte:", []byte(allword3[i+1]))1713 panic("next key error!")1714 }1715 } else {1716 if bfound == true {1717 panic("end next is not valid!")1718 }1719 }1720 }1721 testof2.Close()1722 OrderFileClear(orderpath)1723}1724func TestOrderFilePreviousKeytestsample5(t *testing.T) {1725 orderpath := "testdb/TestOrderFilePreviousKeytestsample5"1726 OrderFileClear(orderpath)1727 seed := time.Now().Unix()1728 fmt.Println("seed:", seed)1729 rand.Seed(seed)1730 testof2, _ := OpenOrderFile(orderpath, 0, 0, nil)1731 allword3 := []string{}1732 allword3map := make(map[string]int, 0)1733 bigword, _ := ioutil.ReadFile("testsample5.txt")1734 lines := strings.Split(string(bigword), "\n")1735 for i := 0; i < len(lines); i++ {1736 if lines[i] == "" {1737 continue1738 }1739 _, be := allword3map[string(lines[i])]1740 if !be {1741 testof2.PushKey([]byte(lines[i]), []byte{})1742 allword3 = append(allword3, string(lines[i]))1743 allword3map[string(lines[i])] = 11744 }1745 }1746 testof2.WaitBufMapEmpty()1747 testof2.Flush()1748 sort.Strings(allword3)1749 if len(allword3) < 100 {1750 fmt.Println("allword3:", allword3)1751 }1752 for i := len(allword3) - 1; i >= 0; i-- {1753 fmt.Println("find previous for :", allword3[i])1754 nextkey, bfound := testof2.PreviousKey([]byte(allword3[i]))1755 if i > 0 {1756 if bfound == false || allword3[i-1] != string(nextkey) {1757 fmt.Println("i", i, "currentkey", allword3[i], "found nextkey:", string(nextkey), "right nextkey:", allword3[i-1])1758 panic("next key error!")1759 }1760 } else {1761 if bfound == true {1762 panic("end next is not valid!")1763 }1764 }1765 }1766 testof2.Close()1767 OrderFileClear(orderpath)1768}1769func TestOrderFilePreviousKeytestsample4(t *testing.T) {1770 orderpath := "testdb/TestOrderFilePreviousKeytestsample4"1771 OrderFileClear(orderpath)1772 seed := time.Now().Unix()1773 fmt.Println("seed:", seed)1774 rand.Seed(seed)1775 endbt := []byte{'\t'}1776 testof2, _ := OpenOrderFile(orderpath, 0, 0, endbt)1777 allword3 := []string{}1778 allword3map := make(map[string]int, 0)1779 bigword, _ := ioutil.ReadFile("testsample4.txt")1780 lines := strings.Split(string(bigword), "\n")1781 for i := 0; i < len(lines); i++ {1782 if lines[i] == "" {1783 continue1784 }1785 _, be := allword3map[string(lines[i])]1786 if !be {1787 testof2.PushKey([]byte(lines[i]), []byte{})1788 allword3 = append(allword3, string(lines[i])+"\t")1789 allword3map[string(lines[i])] = 11790 }1791 }1792 testof2.WaitBufMapEmpty()1793 testof2.Flush()1794 // testof2.markrmpushmap.Range(func(key, val interface{}) bool {1795 // fmt.Println(key, val)1796 // return true1797 // })1798 sort.Strings(allword3)1799 if len(allword3) < 100 {1800 fmt.Println("allword3:", allword3)1801 }1802 for i := len(allword3) - 1; i >= 0; i-- {1803 fmt.Println("find previous for :", allword3[i])1804 nextkey, bfound := testof2.PreviousKey([]byte(allword3[i]))1805 if i > 0 {1806 if bfound == false || allword3[i-1] != string(nextkey) {1807 // testof2.markrmpushmap.Range(func(key, val interface{}) bool {1808 // fmt.Println(key, val)1809 // return true1810 // })1811 fmt.Println("i", i, "currentkey", allword3[i], "found previouskey:", string(nextkey), "right previouskey:", allword3[i-1])1812 panic("previous key error!")1813 }1814 } else {1815 if bfound == true {1816 panic("end next is not valid!")1817 }1818 }1819 }1820 testof2.Close()1821 OrderFileClear(orderpath)1822}1823func TestOrderFilePreviousKeytestsample3(t *testing.T) {1824 orderpath := "testdb/TestOrderFilePreviousKeytestsample3"1825 OrderFileClear(orderpath)1826 seed := time.Now().Unix()1827 fmt.Println("seed:", seed)1828 rand.Seed(seed)1829 testof2, _ := OpenOrderFile(orderpath, 0, 0, nil)1830 allword3 := []string{}1831 allword3map := make(map[string]int, 0)1832 bigword, _ := ioutil.ReadFile("testsample3.txt")1833 lines := strings.Split(string(bigword), "\n")1834 for i := 0; i < len(lines); i++ {1835 if lines[i] == "" {1836 continue1837 }1838 _, be := allword3map[string(lines[i])]1839 if !be {1840 testof2.PushKey([]byte(lines[i]), []byte{})1841 allword3 = append(allword3, string(lines[i]))1842 allword3map[string(lines[i])] = 11843 }1844 }1845 testof2.WaitBufMapEmpty()1846 testof2.Flush()1847 sort.Strings(allword3)1848 if len(allword3) < 100 {1849 fmt.Println("allword3:", allword3)1850 }1851 for i := len(allword3) - 1; i >= 0; i-- {1852 fmt.Println("find previous for :", allword3[i])1853 nextkey, bfound := testof2.PreviousKey([]byte(allword3[i]))1854 if i > 0 {1855 if bfound == false || allword3[i-1] != string(nextkey) {1856 fmt.Println("i", i, "currentkey", allword3[i], "found nextkey:", string(nextkey), "right nextkey:", allword3[i-1])1857 panic("next key error!")1858 }1859 } else {1860 if bfound == true {1861 panic("end next is not valid!")1862 }1863 }1864 }1865 testof2.Close()1866 OrderFileClear(orderpath)1867}1868func TestOrderFilePreviousKeyTestSample2(t *testing.T) {1869 orderpath := "TestOrderFilePreviousKeyTestSample2"1870 OrderFileClear(orderpath)1871 seed := time.Now().Unix()1872 fmt.Println("seed:", seed)1873 rand.Seed(seed)1874 endbt := []byte{0}1875 testof2, _ := OpenOrderFile(orderpath, 0, 0, endbt)1876 allword3 := []string{}1877 bigword, _ := ioutil.ReadFile("testsample2.txt")1878 lines := strings.Split(string(bigword), "\n")1879 for i := 0; i < len(lines); i++ {1880 if lines[i] == "" {1881 continue1882 }1883 testof2.PushKey([]byte(lines[i]), []byte{})1884 allword3 = append(allword3, string(lines[i]))1885 }1886 testof2.WaitBufMapEmpty()1887 testof2.Flush()1888 sort.Strings(allword3)1889 if len(allword3) < 100 {1890 fmt.Println("allword3:", allword3)1891 }1892 for i := len(allword3) - 1; i >= 0; i-- {1893 fmt.Println("find previous for :", allword3[i])1894 nextkey, bfound := testof2.PreviousKey([]byte(allword3[i]))1895 if i > 0 {1896 if bfound == false || allword3[i-1]+string(endbt) != string(nextkey) {1897 fmt.Println("i", i, "found nextkey:", string(nextkey), "right nextkey:", allword3[i-1]+string(endbt))1898 panic("next key error!")1899 }1900 } else {1901 if bfound == true {1902 panic("end next is not valid!")1903 }1904 }1905 }1906 testof2.Close()1907 OrderFileClear(orderpath)1908}1909func TestOrderFilePreviousKeyTestSample1(t *testing.T) {1910 orderpath := "testdb/TestOrderFilePreviousKeyTestSample1"1911 OrderFileClear(orderpath)1912 seed := time.Now().Unix()1913 fmt.Println("seed:", seed)1914 rand.Seed(seed)1915 testof2, _ := OpenOrderFile(orderpath, 0, 0, nil)1916 allword3 := []string{}1917 bigword, _ := ioutil.ReadFile("testsample1.txt")1918 lines := strings.Split(string(bigword), "\n")1919 for i := 0; i < len(lines); i++ {1920 if lines[i] == "" {1921 continue1922 }1923 testof2.PushKey([]byte(lines[i]), []byte{})1924 allword3 = append(allword3, string(lines[i]))1925 }1926 testof2.WaitBufMapEmpty()1927 testof2.Flush()1928 sort.Strings(allword3)1929 for i := len(allword3) - 1; i >= 0; i-- {1930 fmt.Println("find previous for :", allword3[i])1931 nextkey, bfound := testof2.PreviousKey([]byte(allword3[i]))1932 if i > 0 {1933 if bfound == false || allword3[i-1] != string(nextkey) {1934 fmt.Println("i", i, "found nextkey:", string(nextkey), "right nextkey:", allword3[i-1])1935 panic("next key error!")1936 }1937 } else {1938 if bfound == true {1939 panic("end next is not valid!")1940 }1941 }1942 }1943 testof2.Close()1944 OrderFileClear(orderpath)1945}1946func TestOrderFile12(t *testing.T) {1947 orderpath := "testdb/TestOrderFile12"1948 OrderFileClear(orderpath)1949 OrderFileClear(orderpath + ".compress")1950 seed := time.Now().Unix()1951 fmt.Println("seed:", seed)1952 rand.Seed(seed)1953 testof, _ := OpenOrderFile(orderpath, 0, 0, []byte{0})1954 allword2 := make(map[string][]byte, 0)1955 for i := 0; i < 50000; i++ {1956 word := genwordlarge()1957 word2 := genword()1958 _, isword := allword2[string(word2)]1959 if !isword {1960 testof.PushKey(word2, word)1961 allword2[string(word2)] = word1962 }1963 }1964 testof.Flush()1965 testof.Close()1966 DBCompress(orderpath, false, 10)1967 testof, _ = OpenOrderFile(orderpath+".compress", 0, 0, []byte{0})1968 for word3, word2 := range allword2 {1969 fullword, bfill := testof.FillKey([]byte(word3))1970 if bfill == false || string(fullword) != word3+"\x00"+string(word2) {1971 fmt.Println("error", word3+string(word2))1972 fmt.Println(string(fullword))1973 fmt.Println(runtime.Caller(0))1974 panic("error")1975 }1976 }1977 testof.Close()1978 OrderFileClear(orderpath)1979 OrderFileClear(orderpath + ".compress")1980}1981func TestOrderFile17(t *testing.T) {1982 orderpath := "testdb/TestOrderFile17"1983 OrderFileClear(orderpath)1984 testof, _ := OpenOrderFile(orderpath, 0, 0, nil)1985 testof.RmKey([]byte{0, 0, 0, 45, 0})1986 testof.Push([]byte{0, 0, 0, 45, 0, 100, 97, 116, 97, 112, 97, 116, 104, 9, 116, 101, 115, 116, 119, 101, 98, 115, 105, 116, 101, 47, 116, 101, 99, 104, 46, 105, 102, 101, 110, 103, 46, 99, 111, 109, 10, 100, 97, 116, 97, 105, 100, 9, 49})1987 testof.RmKey([]byte{0, 0, 0, 68, 0})1988 testof.Push([]byte{0, 0, 0, 68, 0, 100, 97, 116, 97, 112, 97, 116, 104, 9, 116, 101, 115, 116, 119, 101, 98, 115, 105, 116, 101, 47, 116, 101, 99, 104, 46, 105, 102, 101, 110, 103, 46, 99, 111, 109, 10, 100, 97, 116, 97, 105, 100, 9, 50})1989 testof.RmKey([]byte{0, 0, 0, 101, 0})1990 testof.Push([]byte{0, 0, 0, 101, 0, 100, 97, 116, 97, 112, 97, 116, 104, 9, 116, 101, 115, 116, 119, 101, 98, 115, 105, 116, 101, 47, 116, 101, 99, 104, 46, 105, 102, 101, 110, 103, 46, 99, 111, 109, 10, 100, 97, 116, 97, 105, 100, 9, 50})1991 testof.RmKey([]byte{0, 0, 0, 33, 0})1992 testof.Push([]byte{0, 0, 0, 33, 0, 100, 97, 116, 97, 112, 97, 116, 104, 9, 116, 101, 115, 116, 119, 101, 98, 115, 105, 116, 101, 47, 116, 101, 99, 104, 46, 105, 102, 101, 110, 103, 46, 99, 111, 109, 10, 100, 97, 116, 97, 105, 100, 9, 49})1993 testof.RmKey([]byte{0, 0, 0, 50, 0})1994 testof.Close()1995 OrderFileClear(orderpath)1996}1997func TestOrderFile24(t *testing.T) {1998 orderpath := "testdb/TestOrderFile24"1999 OrderFileClear(orderpath)2000 rand.Seed(time.Now().Unix())2001 endbt := []byte{0}2002 testof, _ := OpenOrderFile(orderpath, 0, 0, endbt)2003 allword2 := make(map[string]string, 0)2004 for i := 0; i < 50000; i++ {2005 //word := genword() //genwordlarge()2006 word2 := genword()2007 testof.PushKey(word2, word2)2008 allword2[string(word2)] = string(word2)2009 fullword, bfill := testof.FillKey(word2)2010 if bfill == false || string(fullword) != string(word2)+string(endbt)+string(word2) {2011 fmt.Println("error", i)2012 fmt.Println("right byte:", []byte(string(word2)+string(endbt)+string(word2)))2013 fmt.Println("get byte:", fullword)2014 panic("error")2015 }2016 }2017 testof.Close()2018 //bigwordtestf.Close()2019 fmt.Println("reload test")2020 testof, _ = OpenOrderFile(orderpath, 0, 0, endbt)2021 for key, val := range allword2 {2022 fullword, bfill := testof.FillKey([]byte(key))2023 if bfill == false || string(fullword) != string(key)+string(endbt)+string(val) {2024 fmt.Println("error", string(key)+string(endbt)+string(val), string(fullword))2025 fmt.Println("right byte:", []byte(string(key)+string(endbt)+string(val)))2026 fmt.Println("get byte:", fullword)2027 panic("error")2028 }2029 }2030 fmt.Println("remove test")2031 for key, _ := range allword2 {2032 rmrl := testof.RmKey([]byte(key))2033 if !rmrl {2034 fmt.Println("error")2035 panic("error")2036 }2037 }2038 for key, _ := range allword2 {2039 fullword, bfill := testof.FillKey([]byte(key))2040 if bfill == true {2041 fmt.Println("error", bfill, fullword)2042 panic("error")2043 }2044 }2045 testof.Close()2046 OrderFileClear(orderpath)2047}2048func TestOrderFile14(t *testing.T) {2049 orderpath := "testdb/TestOrderFile14"2050 OrderFileClear(orderpath)2051 rand.Seed(time.Now().Unix())2052 endbt := []byte{'\t'}2053 testof, _ := OpenOrderFile(orderpath, 0, 0, endbt)2054 allword2 := make(map[string][]byte, 0)2055 for i := 0; i < 5000; i++ {2056 word := genwordlarge()2057 word2 := genword()2058 _, isword := allword2[string(word2)]2059 if !isword {2060 _, err := allword2[string(word2)]2061 if !err {2062 testof.PushKey(word2, word)2063 allword2[string(word2)] = word2064 fullword, bfill := testof.FillKey(word2)2065 if bfill == false || string(fullword) != string(word2)+"\t"+string(word) {2066 fmt.Println("error", string(word2)+"\t"+string(word), string(fullword))2067 fmt.Println(runtime.Caller(0))2068 panic("error")2069 }2070 }2071 }2072 }2073 testof.Close()2074 OrderFileClear(orderpath)2075}2076func TestOrderFile10(t *testing.T) {2077 orderpath := "testdb/TestOrderFile10"2078 OrderFileClear(orderpath)2079 seed := time.Now().Unix()2080 //seed = 16320319432081 fmt.Println("seed:", seed)2082 rand.Seed(seed)2083 endbt := []byte{'\t'}2084 testof, _ := OpenOrderFile(orderpath, 0, 0, endbt)2085 allword2 := make(map[string][]byte, 0)2086 bigwordtestf, _ := os.Create("testdb/testofrd10.txt")2087 for i := 0; i < 5000; i++ {2088 word := genword() //genwordlarge()2089 word2 := genword()2090 bigwordtestf.Write([]byte(string(word) + "\t" + string(word2)))2091 bigwordtestf.Write([]byte("\n"))2092 //fmt.Println("word1:", word, string(word))2093 //fmt.Println("word2:", word2, string(word2))2094 testof.PushKey(word2, word)2095 allword2[string(word2)] = word2096 for word3, word2 := range allword2 {2097 fullword, bfill := testof.FillKey([]byte(word3))2098 if bfill == false || string(fullword) != word3+"\t"+string(word2) {2099 fmt.Println("error", len(allword2), bfill, "right:", word3+"\t"+string(word2), "filled:", string(fullword))2100 time.Sleep(5 * time.Second)2101 fullword, bfill := testof.FillKey([]byte(word3))2102 fmt.Println(bfill, string(fullword))2103 panic("error")2104 }2105 }2106 }2107 bigwordtestf.Close()2108 testof.Close()2109 OrderFileClear(orderpath)2110}2111func TestOrderFile11(t *testing.T) {2112 orderpath := "testdb/TestOrderFile11"2113 OrderFileClear(orderpath)2114 testof, _ := OpenOrderFile(orderpath, 0, 0, nil)2115 testof.RealPush([]byte("abcogkgk"))2116 testof.RealPush([]byte("abckdkfkd"))2117 testof.RealPush([]byte("dsgfadgfd"))2118 testof.RealPush([]byte("zfgghfh"))2119 testof.RealPush([]byte("dsgcfllfg"))2120 fullword, bfill := testof.RealFill([]byte("abcog"))2121 if bfill == false || string(fullword) != "abcogkgk" {2122 fmt.Println("error")2123 panic("error")2124 }2125 fullword, bfill = testof.RealFill([]byte("zfgg"))2126 if bfill == false || string(fullword) != "zfgghfh" {2127 fmt.Println("error")2128 panic("error")2129 }2130 fullword, bfill = testof.RealFill([]byte("dsgc"))2131 if bfill == false || string(fullword) != "dsgcfllfg" {2132 fmt.Println("error")2133 panic("error")2134 }2135 testof.Close()2136 OrderFileClear(orderpath)2137}...
load.go
Source:load.go
1// Copyright 2018 The Go Authors. All rights reserved.2// Use of this source code is governed by a BSD-style3// license that can be found in the LICENSE file.4package modload5import (6 "bytes"7 "errors"8 "fmt"9 "go/build"10 "io/ioutil"11 "os"12 "path"13 "path/filepath"14 "sort"15 "strings"16 "sync"17 "cmd/go/internal/base"18 "cmd/go/internal/cfg"19 "cmd/go/internal/imports"20 "cmd/go/internal/modfetch"21 "cmd/go/internal/modfile"22 "cmd/go/internal/module"23 "cmd/go/internal/mvs"24 "cmd/go/internal/par"25 "cmd/go/internal/search"26 "cmd/go/internal/semver"27 "cmd/go/internal/str"28)29// buildList is the list of modules to use for building packages.30// It is initialized by calling ImportPaths, ImportFromFiles,31// LoadALL, or LoadBuildList, each of which uses loaded.load.32//33// Ideally, exactly ONE of those functions would be called,34// and exactly once. Most of the time, that's true.35// During "go get" it may not be. TODO(rsc): Figure out if36// that restriction can be established, or else document why not.37//38var buildList []module.Version39// loaded is the most recently-used package loader.40// It holds details about individual packages.41//42// Note that loaded.buildList is only valid during a load operation;43// afterward, it is copied back into the global buildList,44// which should be used instead.45var loaded *loader46// ImportPaths returns the set of packages matching the args (patterns),47// adding modules to the build list as needed to satisfy new imports.48func ImportPaths(patterns []string) []*search.Match {49 InitMod()50 var matches []*search.Match51 for _, pattern := range search.CleanPatterns(patterns) {52 m := &search.Match{53 Pattern: pattern,54 Literal: !strings.Contains(pattern, "...") && !search.IsMetaPackage(pattern),55 }56 if m.Literal {57 m.Pkgs = []string{pattern}58 }59 matches = append(matches, m)60 }61 fsDirs := make([][]string, len(matches))62 loaded = newLoader()63 updateMatches := func(iterating bool) {64 for i, m := range matches {65 switch {66 case build.IsLocalImport(m.Pattern) || filepath.IsAbs(m.Pattern):67 // Evaluate list of file system directories on first iteration.68 if fsDirs[i] == nil {69 var dirs []string70 if m.Literal {71 dirs = []string{m.Pattern}72 } else {73 dirs = search.MatchPackagesInFS(m.Pattern).Pkgs74 }75 fsDirs[i] = dirs76 }77 // Make a copy of the directory list and translate to import paths.78 // Note that whether a directory corresponds to an import path79 // changes as the build list is updated, and a directory can change80 // from not being in the build list to being in it and back as81 // the exact version of a particular module increases during82 // the loader iterations.83 m.Pkgs = str.StringList(fsDirs[i])84 for i, pkg := range m.Pkgs {85 dir := pkg86 if !filepath.IsAbs(dir) {87 dir = filepath.Join(cwd, pkg)88 } else {89 dir = filepath.Clean(dir)90 }91 // Note: The checks for @ here are just to avoid misinterpreting92 // the module cache directories (formerly GOPATH/src/mod/foo@v1.5.2/bar).93 // It's not strictly necessary but helpful to keep the checks.94 if dir == ModRoot {95 pkg = Target.Path96 } else if strings.HasPrefix(dir, ModRoot+string(filepath.Separator)) && !strings.Contains(dir[len(ModRoot):], "@") {97 suffix := filepath.ToSlash(dir[len(ModRoot):])98 if strings.HasPrefix(suffix, "/vendor/") {99 // TODO getmode vendor check100 pkg = strings.TrimPrefix(suffix, "/vendor/")101 } else {102 pkg = Target.Path + suffix103 }104 } else if sub := search.InDir(dir, cfg.GOROOTsrc); sub != "" && !strings.Contains(sub, "@") {105 pkg = filepath.ToSlash(sub)106 } else if path := pathInModuleCache(dir); path != "" {107 pkg = path108 } else {109 pkg = ""110 if !iterating {111 base.Errorf("go: directory %s outside available modules", base.ShortPath(dir))112 }113 }114 info, err := os.Stat(dir)115 if err != nil || !info.IsDir() {116 // If the directory does not exist,117 // don't turn it into an import path118 // that will trigger a lookup.119 pkg = ""120 if !iterating {121 if err != nil {122 base.Errorf("go: no such directory %v", m.Pattern)123 } else {124 base.Errorf("go: %s is not a directory", m.Pattern)125 }126 }127 }128 m.Pkgs[i] = pkg129 }130 case strings.Contains(m.Pattern, "..."):131 m.Pkgs = matchPackages(m.Pattern, loaded.tags, true, buildList)132 case m.Pattern == "all":133 loaded.testAll = true134 if iterating {135 // Enumerate the packages in the main module.136 // We'll load the dependencies as we find them.137 m.Pkgs = matchPackages("...", loaded.tags, false, []module.Version{Target})138 } else {139 // Starting with the packages in the main module,140 // enumerate the full list of "all".141 m.Pkgs = loaded.computePatternAll(m.Pkgs)142 }143 case search.IsMetaPackage(m.Pattern): // std, cmd144 if len(m.Pkgs) == 0 {145 m.Pkgs = search.MatchPackages(m.Pattern).Pkgs146 }147 }148 }149 }150 loaded.load(func() []string {151 var roots []string152 updateMatches(true)153 for _, m := range matches {154 for _, pkg := range m.Pkgs {155 if pkg != "" {156 roots = append(roots, pkg)157 }158 }159 }160 return roots161 })162 // One last pass to finalize wildcards.163 updateMatches(false)164 // A given module path may be used as itself or as a replacement for another165 // module, but not both at the same time. Otherwise, the aliasing behavior is166 // too subtle (see https://golang.org/issue/26607), and we don't want to167 // commit to a specific behavior at this point.168 firstPath := make(map[module.Version]string, len(buildList))169 for _, mod := range buildList {170 src := mod171 if rep := Replacement(mod); rep.Path != "" {172 src = rep173 }174 if prev, ok := firstPath[src]; !ok {175 firstPath[src] = mod.Path176 } else if prev != mod.Path {177 base.Errorf("go: %s@%s used for two different module paths (%s and %s)", src.Path, src.Version, prev, mod.Path)178 }179 }180 base.ExitIfErrors()181 WriteGoMod()182 search.WarnUnmatched(matches)183 return matches184}185// pathInModuleCache returns the import path of the directory dir,186// if dir is in the module cache copy of a module in our build list.187func pathInModuleCache(dir string) string {188 for _, m := range buildList[1:] {189 root, err := modfetch.DownloadDir(m)190 if err != nil {191 continue192 }193 if sub := search.InDir(dir, root); sub != "" {194 sub = filepath.ToSlash(sub)195 if !strings.Contains(sub, "/vendor/") && !strings.HasPrefix(sub, "vendor/") && !strings.Contains(sub, "@") {196 return path.Join(m.Path, filepath.ToSlash(sub))197 }198 }199 }200 return ""201}202// warnPattern returns list, the result of matching pattern,203// but if list is empty then first it prints a warning about204// the pattern not matching any packages.205func warnPattern(pattern string, list []string) []string {206 if len(list) == 0 {207 fmt.Fprintf(os.Stderr, "warning: %q matched no packages\n", pattern)208 }209 return list210}211// ImportFromFiles adds modules to the build list as needed212// to satisfy the imports in the named Go source files.213func ImportFromFiles(gofiles []string) {214 InitMod()215 imports, testImports, err := imports.ScanFiles(gofiles, imports.Tags())216 if err != nil {217 base.Fatalf("go: %v", err)218 }219 loaded = newLoader()220 loaded.load(func() []string {221 var roots []string222 roots = append(roots, imports...)223 roots = append(roots, testImports...)224 return roots225 })226 WriteGoMod()227}228// DirImportPath returns the effective import path for dir,229// provided it is within the main module, or else returns ".".230func DirImportPath(dir string) string {231 if !filepath.IsAbs(dir) {232 dir = filepath.Join(cwd, dir)233 } else {234 dir = filepath.Clean(dir)235 }236 if dir == ModRoot {237 return Target.Path238 }239 if strings.HasPrefix(dir, ModRoot+string(filepath.Separator)) {240 suffix := filepath.ToSlash(dir[len(ModRoot):])241 if strings.HasPrefix(suffix, "/vendor/") {242 return strings.TrimPrefix(suffix, "/vendor/")243 }244 return Target.Path + suffix245 }246 return "."247}248// LoadBuildList loads and returns the build list from go.mod.249// The loading of the build list happens automatically in ImportPaths:250// LoadBuildList need only be called if ImportPaths is not251// (typically in commands that care about the module but252// no particular package).253func LoadBuildList() []module.Version {254 InitMod()255 ReloadBuildList()256 WriteGoMod()257 return buildList258}259func ReloadBuildList() []module.Version {260 loaded = newLoader()261 loaded.load(func() []string { return nil })262 return buildList263}264// LoadALL returns the set of all packages in the current module265// and their dependencies in any other modules, without filtering266// due to build tags, except "+build ignore".267// It adds modules to the build list as needed to satisfy new imports.268// This set is useful for deciding whether a particular import is needed269// anywhere in a module.270func LoadALL() []string {271 return loadAll(true)272}273// LoadVendor is like LoadALL but only follows test dependencies274// for tests in the main module. Tests in dependency modules are275// ignored completely.276// This set is useful for identifying the which packages to include in a vendor directory.277func LoadVendor() []string {278 return loadAll(false)279}280func loadAll(testAll bool) []string {281 InitMod()282 loaded = newLoader()283 loaded.isALL = true284 loaded.tags = anyTags285 loaded.testAll = testAll286 if !testAll {287 loaded.testRoots = true288 }289 all := TargetPackages()290 loaded.load(func() []string { return all })291 WriteGoMod()292 var paths []string293 for _, pkg := range loaded.pkgs {294 if e, ok := pkg.err.(*ImportMissingError); ok && e.Module.Path == "" {295 continue // Package doesn't actually exist.296 }297 paths = append(paths, pkg.path)298 }299 return paths300}301// anyTags is a special tags map that satisfies nearly all build tag expressions.302// Only "ignore" and malformed build tag requirements are considered false.303var anyTags = map[string]bool{"*": true}304// TargetPackages returns the list of packages in the target (top-level) module,305// under all build tag settings.306func TargetPackages() []string {307 return matchPackages("...", anyTags, false, []module.Version{Target})308}309// BuildList returns the module build list,310// typically constructed by a previous call to311// LoadBuildList or ImportPaths.312// The caller must not modify the returned list.313func BuildList() []module.Version {314 return buildList315}316// SetBuildList sets the module build list.317// The caller is responsible for ensuring that the list is valid.318// SetBuildList does not retain a reference to the original list.319func SetBuildList(list []module.Version) {320 buildList = append([]module.Version{}, list...)321}322// ImportMap returns the actual package import path323// for an import path found in source code.324// If the given import path does not appear in the source code325// for the packages that have been loaded, ImportMap returns the empty string.326func ImportMap(path string) string {327 pkg, ok := loaded.pkgCache.Get(path).(*loadPkg)328 if !ok {329 return ""330 }331 return pkg.path332}333// PackageDir returns the directory containing the source code334// for the package named by the import path.335func PackageDir(path string) string {336 pkg, ok := loaded.pkgCache.Get(path).(*loadPkg)337 if !ok {338 return ""339 }340 return pkg.dir341}342// PackageModule returns the module providing the package named by the import path.343func PackageModule(path string) module.Version {344 pkg, ok := loaded.pkgCache.Get(path).(*loadPkg)345 if !ok {346 return module.Version{}347 }348 return pkg.mod349}350// ModuleUsedDirectly reports whether the main module directly imports351// some package in the module with the given path.352func ModuleUsedDirectly(path string) bool {353 return loaded.direct[path]354}355// Lookup returns the source directory, import path, and any loading error for356// the package at path.357// Lookup requires that one of the Load functions in this package has already358// been called.359func Lookup(path string) (dir, realPath string, err error) {360 pkg, ok := loaded.pkgCache.Get(path).(*loadPkg)361 if !ok {362 // The loader should have found all the relevant paths.363 // There are a few exceptions, though:364 // - during go list without -test, the p.Resolve calls to process p.TestImports and p.XTestImports365 // end up here to canonicalize the import paths.366 // - during any load, non-loaded packages like "unsafe" end up here.367 // - during any load, build-injected dependencies like "runtime/cgo" end up here.368 // - because we ignore appengine/* in the module loader,369 // the dependencies of any actual appengine/* library end up here.370 dir := findStandardImportPath(path)371 if dir != "" {372 return dir, path, nil373 }374 return "", "", errMissing375 }376 return pkg.dir, pkg.path, pkg.err377}378// A loader manages the process of loading information about379// the required packages for a particular build,380// checking that the packages are available in the module set,381// and updating the module set if needed.382// Loading is an iterative process: try to load all the needed packages,383// but if imports are missing, try to resolve those imports, and repeat.384//385// Although most of the loading state is maintained in the loader struct,386// one key piece - the build list - is a global, so that it can be modified387// separate from the loading operation, such as during "go get"388// upgrades/downgrades or in "go mod" operations.389// TODO(rsc): It might be nice to make the loader take and return390// a buildList rather than hard-coding use of the global.391type loader struct {392 tags map[string]bool // tags for scanDir393 testRoots bool // include tests for roots394 isALL bool // created with LoadALL395 testAll bool // include tests for all packages396 // reset on each iteration397 roots []*loadPkg398 pkgs []*loadPkg399 work *par.Work // current work queue400 pkgCache *par.Cache // map from string to *loadPkg401 // computed at end of iterations402 direct map[string]bool // imported directly by main module403 goVersion map[string]string // go version recorded in each module404}405// LoadTests controls whether the loaders load tests of the root packages.406var LoadTests bool407func newLoader() *loader {408 ld := new(loader)409 ld.tags = imports.Tags()410 ld.testRoots = LoadTests411 return ld412}413func (ld *loader) reset() {414 ld.roots = nil415 ld.pkgs = nil416 ld.work = new(par.Work)417 ld.pkgCache = new(par.Cache)418}419// A loadPkg records information about a single loaded package.420type loadPkg struct {421 path string // import path422 mod module.Version // module providing package423 dir string // directory containing source code424 imports []*loadPkg // packages imported by this one425 err error // error loading package426 stack *loadPkg // package importing this one in minimal import stack for this pkg427 test *loadPkg // package with test imports, if we need test428 testOf *loadPkg429 testImports []string // test-only imports, saved for use by pkg.test.430}431var errMissing = errors.New("cannot find package")432// load attempts to load the build graph needed to process a set of root packages.433// The set of root packages is defined by the addRoots function,434// which must call add(path) with the import path of each root package.435func (ld *loader) load(roots func() []string) {436 var err error437 reqs := Reqs()438 buildList, err = mvs.BuildList(Target, reqs)439 if err != nil {440 base.Fatalf("go: %v", err)441 }442 added := make(map[string]bool)443 for {444 ld.reset()445 if roots != nil {446 // Note: the returned roots can change on each iteration,447 // since the expansion of package patterns depends on the448 // build list we're using.449 for _, path := range roots() {450 ld.work.Add(ld.pkg(path, true))451 }452 }453 ld.work.Do(10, ld.doPkg)454 ld.buildStacks()455 numAdded := 0456 haveMod := make(map[module.Version]bool)457 for _, m := range buildList {458 haveMod[m] = true459 }460 for _, pkg := range ld.pkgs {461 if err, ok := pkg.err.(*ImportMissingError); ok && err.Module.Path != "" {462 if added[pkg.path] {463 base.Fatalf("go: %s: looping trying to add package", pkg.stackText())464 }465 added[pkg.path] = true466 numAdded++467 if !haveMod[err.Module] {468 haveMod[err.Module] = true469 buildList = append(buildList, err.Module)470 }471 continue472 }473 // Leave other errors for Import or load.Packages to report.474 }475 base.ExitIfErrors()476 if numAdded == 0 {477 break478 }479 // Recompute buildList with all our additions.480 reqs = Reqs()481 buildList, err = mvs.BuildList(Target, reqs)482 if err != nil {483 base.Fatalf("go: %v", err)484 }485 }486 base.ExitIfErrors()487 // Compute directly referenced dependency modules.488 ld.direct = make(map[string]bool)489 for _, pkg := range ld.pkgs {490 if pkg.mod == Target {491 for _, dep := range pkg.imports {492 if dep.mod.Path != "" {493 ld.direct[dep.mod.Path] = true494 }495 }496 }497 }498 // Add Go versions, computed during walk.499 ld.goVersion = make(map[string]string)500 for _, m := range buildList {501 v, _ := reqs.(*mvsReqs).versions.Load(m)502 ld.goVersion[m.Path], _ = v.(string)503 }504 // Mix in direct markings (really, lack of indirect markings)505 // from go.mod, unless we scanned the whole module506 // and can therefore be sure we know better than go.mod.507 if !ld.isALL && modFile != nil {508 for _, r := range modFile.Require {509 if !r.Indirect {510 ld.direct[r.Mod.Path] = true511 }512 }513 }514}515// pkg returns the *loadPkg for path, creating and queuing it if needed.516// If the package should be tested, its test is created but not queued517// (the test is queued after processing pkg).518// If isRoot is true, the pkg is being queued as one of the roots of the work graph.519func (ld *loader) pkg(path string, isRoot bool) *loadPkg {520 return ld.pkgCache.Do(path, func() interface{} {521 pkg := &loadPkg{522 path: path,523 }524 if ld.testRoots && isRoot || ld.testAll {525 test := &loadPkg{526 path: path,527 testOf: pkg,528 }529 pkg.test = test530 }531 if isRoot {532 ld.roots = append(ld.roots, pkg)533 }534 ld.work.Add(pkg)535 return pkg536 }).(*loadPkg)537}538// doPkg processes a package on the work queue.539func (ld *loader) doPkg(item interface{}) {540 // TODO: what about replacements?541 pkg := item.(*loadPkg)542 var imports []string543 if pkg.testOf != nil {544 pkg.dir = pkg.testOf.dir545 pkg.mod = pkg.testOf.mod546 imports = pkg.testOf.testImports547 } else {548 if strings.Contains(pkg.path, "@") {549 // Leave for error during load.550 return551 }552 if build.IsLocalImport(pkg.path) {553 // Leave for error during load.554 // (Module mode does not allow local imports.)555 return556 }557 pkg.mod, pkg.dir, pkg.err = Import(pkg.path)558 if pkg.dir == "" {559 return560 }561 var testImports []string562 var err error563 imports, testImports, err = scanDir(pkg.dir, ld.tags)564 if err != nil {565 pkg.err = err566 return567 }568 if pkg.test != nil {569 pkg.testImports = testImports570 }571 }572 for _, path := range imports {573 pkg.imports = append(pkg.imports, ld.pkg(path, false))574 }575 // Now that pkg.dir, pkg.mod, pkg.testImports are set, we can queue pkg.test.576 // TODO: All that's left is creating new imports. Why not just do it now?577 if pkg.test != nil {578 ld.work.Add(pkg.test)579 }580}581// computePatternAll returns the list of packages matching pattern "all",582// starting with a list of the import paths for the packages in the main module.583func (ld *loader) computePatternAll(paths []string) []string {584 seen := make(map[*loadPkg]bool)585 var all []string586 var walk func(*loadPkg)587 walk = func(pkg *loadPkg) {588 if seen[pkg] {589 return590 }591 seen[pkg] = true592 if pkg.testOf == nil {593 all = append(all, pkg.path)594 }595 for _, p := range pkg.imports {596 walk(p)597 }598 if p := pkg.test; p != nil {599 walk(p)600 }601 }602 for _, path := range paths {603 walk(ld.pkg(path, false))604 }605 sort.Strings(all)606 return all607}608// scanDir is like imports.ScanDir but elides known magic imports from the list,609// so that we do not go looking for packages that don't really exist.610//611// The standard magic import is "C", for cgo.612//613// The only other known magic imports are appengine and appengine/*.614// These are so old that they predate "go get" and did not use URL-like paths.615// Most code today now uses google.golang.org/appengine instead,616// but not all code has been so updated. When we mostly ignore build tags617// during "go vendor", we look into "// +build appengine" files and618// may see these legacy imports. We drop them so that the module619// search does not look for modules to try to satisfy them.620func scanDir(dir string, tags map[string]bool) (imports_, testImports []string, err error) {621 imports_, testImports, err = imports.ScanDir(dir, tags)622 filter := func(x []string) []string {623 w := 0624 for _, pkg := range x {625 if pkg != "C" && pkg != "appengine" && !strings.HasPrefix(pkg, "appengine/") &&626 pkg != "appengine_internal" && !strings.HasPrefix(pkg, "appengine_internal/") {627 x[w] = pkg628 w++629 }630 }631 return x[:w]632 }633 return filter(imports_), filter(testImports), err634}635// buildStacks computes minimal import stacks for each package,636// for use in error messages. When it completes, packages that637// are part of the original root set have pkg.stack == nil,638// and other packages have pkg.stack pointing at the next639// package up the import stack in their minimal chain.640// As a side effect, buildStacks also constructs ld.pkgs,641// the list of all packages loaded.642func (ld *loader) buildStacks() {643 if len(ld.pkgs) > 0 {644 panic("buildStacks")645 }646 for _, pkg := range ld.roots {647 pkg.stack = pkg // sentinel to avoid processing in next loop648 ld.pkgs = append(ld.pkgs, pkg)649 }650 for i := 0; i < len(ld.pkgs); i++ { // not range: appending to ld.pkgs in loop651 pkg := ld.pkgs[i]652 for _, next := range pkg.imports {653 if next.stack == nil {654 next.stack = pkg655 ld.pkgs = append(ld.pkgs, next)656 }657 }658 if next := pkg.test; next != nil && next.stack == nil {659 next.stack = pkg660 ld.pkgs = append(ld.pkgs, next)661 }662 }663 for _, pkg := range ld.roots {664 pkg.stack = nil665 }666}667// stackText builds the import stack text to use when668// reporting an error in pkg. It has the general form669//670// import root ->671// import other ->672// import other2 ->673// import pkg674//675func (pkg *loadPkg) stackText() string {676 var stack []*loadPkg677 for p := pkg.stack; p != nil; p = p.stack {678 stack = append(stack, p)679 }680 var buf bytes.Buffer681 for i := len(stack) - 1; i >= 0; i-- {682 p := stack[i]683 if p.testOf != nil {684 fmt.Fprintf(&buf, "test ->\n\t")685 } else {686 fmt.Fprintf(&buf, "import %q ->\n\t", p.path)687 }688 }689 fmt.Fprintf(&buf, "import %q", pkg.path)690 return buf.String()691}692// why returns the text to use in "go mod why" output about the given package.693// It is less ornate than the stackText but conatins the same information.694func (pkg *loadPkg) why() string {695 var buf strings.Builder696 var stack []*loadPkg697 for p := pkg; p != nil; p = p.stack {698 stack = append(stack, p)699 }700 for i := len(stack) - 1; i >= 0; i-- {701 p := stack[i]702 if p.testOf != nil {703 fmt.Fprintf(&buf, "%s.test\n", p.testOf.path)704 } else {705 fmt.Fprintf(&buf, "%s\n", p.path)706 }707 }708 return buf.String()709}710// Why returns the "go mod why" output stanza for the given package,711// without the leading # comment.712// The package graph must have been loaded already, usually by LoadALL.713// If there is no reason for the package to be in the current build,714// Why returns an empty string.715func Why(path string) string {716 pkg, ok := loaded.pkgCache.Get(path).(*loadPkg)717 if !ok {718 return ""719 }720 return pkg.why()721}722// WhyDepth returns the number of steps in the Why listing.723// If there is no reason for the package to be in the current build,724// WhyDepth returns 0.725func WhyDepth(path string) int {726 n := 0727 pkg, _ := loaded.pkgCache.Get(path).(*loadPkg)728 for p := pkg; p != nil; p = p.stack {729 n++730 }731 return n732}733// Replacement returns the replacement for mod, if any, from go.mod.734// If there is no replacement for mod, Replacement returns735// a module.Version with Path == "".736func Replacement(mod module.Version) module.Version {737 if modFile == nil {738 // Happens during testing.739 return module.Version{}740 }741 var found *modfile.Replace742 for _, r := range modFile.Replace {743 if r.Old.Path == mod.Path && (r.Old.Version == "" || r.Old.Version == mod.Version) {744 found = r // keep going745 }746 }747 if found == nil {748 return module.Version{}749 }750 return found.New751}752// mvsReqs implements mvs.Reqs for module semantic versions,753// with any exclusions or replacements applied internally.754type mvsReqs struct {755 buildList []module.Version756 cache par.Cache757 versions sync.Map758}759// Reqs returns the current module requirement graph.760// Future calls to SetBuildList do not affect the operation761// of the returned Reqs.762func Reqs() mvs.Reqs {763 r := &mvsReqs{764 buildList: buildList,765 }766 return r767}768func (r *mvsReqs) Required(mod module.Version) ([]module.Version, error) {769 type cached struct {770 list []module.Version771 err error772 }773 c := r.cache.Do(mod, func() interface{} {774 list, err := r.required(mod)775 if err != nil {776 return cached{nil, err}777 }778 for i, mv := range list {779 for excluded[mv] {780 mv1, err := r.next(mv)781 if err != nil {782 return cached{nil, err}783 }784 if mv1.Version == "none" {785 return cached{nil, fmt.Errorf("%s(%s) depends on excluded %s(%s) with no newer version available", mod.Path, mod.Version, mv.Path, mv.Version)}786 }787 mv = mv1788 }789 list[i] = mv790 }791 return cached{list, nil}792 }).(cached)793 return c.list, c.err794}795var vendorOnce sync.Once796var (797 vendorList []module.Version798 vendorMap map[string]module.Version799)800// readVendorList reads the list of vendored modules from vendor/modules.txt.801func readVendorList() {802 vendorOnce.Do(func() {803 vendorList = nil804 vendorMap = make(map[string]module.Version)805 data, _ := ioutil.ReadFile(filepath.Join(ModRoot, "vendor/modules.txt"))806 var m module.Version807 for _, line := range strings.Split(string(data), "\n") {808 if strings.HasPrefix(line, "# ") {809 f := strings.Fields(line)810 m = module.Version{}811 if len(f) == 3 && semver.IsValid(f[2]) {812 m = module.Version{Path: f[1], Version: f[2]}813 vendorList = append(vendorList, m)814 }815 } else if m.Path != "" {816 f := strings.Fields(line)817 if len(f) == 1 {818 vendorMap[f[0]] = m819 }820 }821 }822 })823}824func (r *mvsReqs) modFileToList(f *modfile.File) []module.Version {825 var list []module.Version826 for _, r := range f.Require {827 list = append(list, r.Mod)828 }829 return list830}831func (r *mvsReqs) required(mod module.Version) ([]module.Version, error) {832 if mod == Target {833 if modFile.Go != nil {834 r.versions.LoadOrStore(mod, modFile.Go.Version)835 }836 var list []module.Version837 return append(list, r.buildList[1:]...), nil838 }839 if cfg.BuildMod == "vendor" {840 // For every module other than the target,841 // return the full list of modules from modules.txt.842 readVendorList()843 return vendorList, nil844 }845 origPath := mod.Path846 if repl := Replacement(mod); repl.Path != "" {847 if repl.Version == "" {848 // TODO: need to slip the new version into the tags list etc.849 dir := repl.Path850 if !filepath.IsAbs(dir) {851 dir = filepath.Join(ModRoot, dir)852 }853 gomod := filepath.Join(dir, "go.mod")854 data, err := ioutil.ReadFile(gomod)855 if err != nil {856 base.Errorf("go: parsing %s: %v", base.ShortPath(gomod), err)857 return nil, ErrRequire858 }859 f, err := modfile.ParseLax(gomod, data, nil)860 if err != nil {861 base.Errorf("go: parsing %s: %v", base.ShortPath(gomod), err)862 return nil, ErrRequire863 }864 if f.Go != nil {865 r.versions.LoadOrStore(mod, f.Go.Version)866 }867 return r.modFileToList(f), nil868 }869 mod = repl870 }871 if mod.Version == "none" {872 return nil, nil873 }874 if !semver.IsValid(mod.Version) {875 // Disallow the broader queries supported by fetch.Lookup.876 base.Fatalf("go: internal error: %s@%s: unexpected invalid semantic version", mod.Path, mod.Version)877 }878 data, err := modfetch.GoMod(mod.Path, mod.Version)879 if err != nil {880 base.Errorf("go: %s@%s: %v\n", mod.Path, mod.Version, err)881 return nil, ErrRequire882 }883 f, err := modfile.ParseLax("go.mod", data, nil)884 if err != nil {885 base.Errorf("go: %s@%s: parsing go.mod: %v", mod.Path, mod.Version, err)886 return nil, ErrRequire887 }888 if f.Module == nil {889 base.Errorf("go: %s@%s: parsing go.mod: missing module line", mod.Path, mod.Version)890 return nil, ErrRequire891 }892 if mpath := f.Module.Mod.Path; mpath != origPath && mpath != mod.Path {893 base.Errorf("go: %s@%s: parsing go.mod: unexpected module path %q", mod.Path, mod.Version, mpath)894 return nil, ErrRequire895 }896 if f.Go != nil {897 r.versions.LoadOrStore(mod, f.Go.Version)898 }899 return r.modFileToList(f), nil900}901// ErrRequire is the sentinel error returned when Require encounters problems.902// It prints the problems directly to standard error, so that multiple errors903// can be displayed easily.904var ErrRequire = errors.New("error loading module requirements")905func (*mvsReqs) Max(v1, v2 string) string {906 if v1 != "" && semver.Compare(v1, v2) == -1 {907 return v2908 }909 return v1910}911// Upgrade is a no-op, here to implement mvs.Reqs.912// The upgrade logic for go get -u is in ../modget/get.go.913func (*mvsReqs) Upgrade(m module.Version) (module.Version, error) {914 return m, nil915}916func versions(path string) ([]string, error) {917 // Note: modfetch.Lookup and repo.Versions are cached,918 // so there's no need for us to add extra caching here.919 repo, err := modfetch.Lookup(path)920 if err != nil {921 return nil, err922 }923 return repo.Versions("")924}925// Previous returns the tagged version of m.Path immediately prior to926// m.Version, or version "none" if no prior version is tagged.927func (*mvsReqs) Previous(m module.Version) (module.Version, error) {928 list, err := versions(m.Path)929 if err != nil {930 return module.Version{}, err931 }932 i := sort.Search(len(list), func(i int) bool { return semver.Compare(list[i], m.Version) >= 0 })933 if i > 0 {934 return module.Version{Path: m.Path, Version: list[i-1]}, nil935 }936 return module.Version{Path: m.Path, Version: "none"}, nil937}938// next returns the next version of m.Path after m.Version.939// It is only used by the exclusion processing in the Required method,940// not called directly by MVS.941func (*mvsReqs) next(m module.Version) (module.Version, error) {942 list, err := versions(m.Path)943 if err != nil {944 return module.Version{}, err945 }946 i := sort.Search(len(list), func(i int) bool { return semver.Compare(list[i], m.Version) > 0 })947 if i < len(list) {948 return module.Version{Path: m.Path, Version: list[i]}, nil949 }950 return module.Version{Path: m.Path, Version: "none"}, nil951}952func fetch(mod module.Version) (dir string, isLocal bool, err error) {953 if mod == Target {954 return ModRoot, true, nil955 }956 if r := Replacement(mod); r.Path != "" {957 if r.Version == "" {958 dir = r.Path959 if !filepath.IsAbs(dir) {960 dir = filepath.Join(ModRoot, dir)961 }962 return dir, true, nil963 }964 mod = r965 }966 dir, err = modfetch.Download(mod)967 return dir, false, err968}...
TestOf
Using AI Code Generation
1import (2func main() {3 s.Add(1)4 s.Add(2)5 s.Add(3)6 s.Add(4)7 s.Add(5)8 s.Add(6)9 s.Add(7)10 s.Add(8)11 s.Add(9)12 s.Add(10)13 s.Add(11)14 s.Add(12)15 s.Add(13)16 s.Add(14)17 s.Add(15)18 s.Add(16)19 s.Add(17)20 s.Add(18)21 s.Add(19)22 s.Add(20)23 s.Add(21)24 s.Add(22)25 s.Add(23)26 s.Add(24)27 s.Add(25)28 s.Add(26)29 s.Add(27)30 s.Add(28)31 s.Add(29)32 s.Add(30)33 s.Add(31)34 s.Add(32)35 s.Add(33)36 s.Add(34)37 s.Add(35)38 s.Add(36)39 s.Add(37)40 s.Add(38)41 s.Add(39)42 s.Add(40)43 s.Add(41)44 s.Add(42)45 s.Add(43)46 s.Add(44)47 s.Add(45)48 s.Add(46)49 s.Add(47)50 s.Add(48)51 s.Add(49)52 s.Add(50)53 s.Add(51)54 s.Add(52)55 s.Add(53)56 s.Add(54)57 s.Add(55)58 s.Add(56)59 s.Add(57)60 s.Add(58)61 s.Add(59)62 s.Add(60)63 s.Add(61)64 s.Add(62)65 s.Add(63)66 s.Add(64)67 s.Add(65)68 s.Add(66)69 s.Add(67)70 s.Add(68)71 s.Add(69)72 s.Add(70)73 s.Add(71)74 s.Add(72)75 s.Add(73)76 s.Add(74)77 s.Add(75)78 s.Add(76)79 s.Add(77)80 s.Add(78)81 s.Add(79)82 s.Add(80)83 s.Add(81)84 s.Add(82)85 s.Add(83)86 s.Add(84)87 s.Add(85)88 s.Add(86)89 s.Add(87)90 s.Add(88)91 s.Add(89)92 s.Add(90)93 s.Add(91)94 s.Add(92)95 s.Add(93)96 s.Add(94)97 s.Add(95)
TestOf
Using AI Code Generation
1import (2func main() {3 s := set.NewSet()4 s.Add("1")5 s.Add("2")6 s.Add("3")7 s.Add("4")8 s.Add("5")9 s.Add("6")10 s.Add("7")11 s.Add("8")12 s.Add("9")13 s.Add("10")14 s.Add("11")15 s.Add("12")16 s.Add("13")17 s.Add("14")18 s.Add("15")19 s.Add("16")20 s.Add("17")21 s.Add("18")22 s.Add("19")23 s.Add("20")24 s.Add("21")25 s.Add("22")26 s.Add("23")27 s.Add("24")28 s.Add("25")29 s.Add("26")30 s.Add("27")31 s.Add("28")32 s.Add("29")33 s.Add("30")34 s.Add("31")35 s.Add("32")36 s.Add("33")37 s.Add("34")38 s.Add("35")39 s.Add("36")40 s.Add("37")41 s.Add("38")42 s.Add("39")43 s.Add("40")44 s.Add("41")45 s.Add("42")46 s.Add("43")47 s.Add("44")48 s.Add("45")49 s.Add("46")50 s.Add("47")51 s.Add("48")52 s.Add("49")53 s.Add("50")54 s.Add("51")55 s.Add("52")56 s.Add("53")57 s.Add("54")58 s.Add("55")59 s.Add("56")60 s.Add("57")61 s.Add("58")62 s.Add("59")63 s.Add("60")64 s.Add("61")65 s.Add("62")66 s.Add("63")67 s.Add("64")68 s.Add("65")69 s.Add("66")70 s.Add("67")71 s.Add("68")72 s.Add("69")73 s.Add("70")74 s.Add("71")75 s.Add("72")76 s.Add("73")77 s.Add("74")78 s.Add("75")79 s.Add("76")80 s.Add("77")81 s.Add("78")82 s.Add("79")83 s.Add("80")84 s.Add("81")85 s.Add("82")86 s.Add("83")87 s.Add("84")88 s.Add("85")89 s.Add("86")90 s.Add("87")91 s.Add("88")92 s.Add("89")93 s.Add("90")94 s.Add("91")95 s.Add("92")96 s.Add("93")97 s.Add("94")98 s.Add("95")
TestOf
Using AI Code Generation
1import (2func main() {3 s := set.NewSet()4 s.Add(1)5 s.Add(2)6 s.Add(3)7 s.Add(4)8 s.Add(5)9 s.Add(6)10 s.Add(7)11 s.Add(8)12 s.Add(9)13 s.Add(10)14 if s.TestOf(1) {15 fmt.Println("1 is present in the set")16 } else {17 fmt.Println("1 is not present in the set")18 }19 if s.TestOf(11) {20 fmt.Println("11 is present in the set")21 } else {22 fmt.Println("11 is not present in the set")23 }24}25import (26func main() {27 s := set.NewSet()28 s.Add(1)29 s.Add(2)30 s.Add(3)31 s.Add(4)32 s.Add(5)33 s.Add(6)34 s.Add(7)35 s.Add(8)36 s.Add(9)37 s.Add(10)38 s.Remove(1)39 if s.TestOf(1) {40 fmt.Println("1 is present in the set")41 } else {42 fmt.Println("1 is not present in the set")43 }44 if s.TestOf(11) {45 fmt.Println("11 is present in the set")46 } else {47 fmt.Println("11 is not present in the set")48 }49}50import (51func main() {52 s := set.NewSet()53 s.Add(1)54 s.Add(2)55 s.Add(3)56 s.Add(4)57 s.Add(5)58 s.Add(6)59 s.Add(7)60 s.Add(
TestOf
Using AI Code Generation
1import (2func main() {3 g1 := gsd.Graph("g1")4 g1.AddEdge("a", "b", 1)5 g1.AddEdge("a", "c", 1)6 g1.AddEdge("a", "d", 1)7 g1.AddEdge("b", "e", 1)8 g1.AddEdge("b", "f", 1)9 g1.AddEdge("c", "g", 1)10 g1.AddEdge("c", "h", 1)11 g1.AddEdge("d", "i", 1)12 g1.AddEdge("d", "j", 1)13 g1.AddEdge("e", "k", 1)14 g1.AddEdge("e", "l", 1)15 g1.AddEdge("f", "m", 1)16 g1.AddEdge("f", "n", 1)17 g1.AddEdge("g", "o", 1)18 g1.AddEdge("g", "p", 1)19 g1.AddEdge("h", "q", 1)20 g1.AddEdge("h", "r", 1)21 g1.AddEdge("i", "s", 1)22 g1.AddEdge("i", "t", 1)23 g1.AddEdge("j", "u", 1)24 g1.AddEdge("j", "v", 1)25 g1.AddEdge("k", "w", 1)26 g1.AddEdge("k", "x", 1)27 g1.AddEdge("l", "y", 1)28 g1.AddEdge("l", "z", 1)29 g1.AddEdge("m", "aa", 1)30 g1.AddEdge("m", "bb", 1)31 g1.AddEdge("n", "cc", 1)32 g1.AddEdge("n", "dd", 1)33 g1.AddEdge("o", "ee", 1)34 g1.AddEdge("o", "ff", 1)35 g1.AddEdge("p", "gg", 1)36 g1.AddEdge("p", "hh
TestOf
Using AI Code Generation
1import (2func main() {3 set1.Add(1)4 set1.Add(2)5 set1.Add(3)6 set1.Add(4)7 set1.Add(5)8 set1.Add(6)9 set1.Add(7)10 set2.Add(1)11 set2.Add(2)12 set2.Add(3)13 set2.Add(4)14 set2.Add(5)15 set2.Add(6)16 set2.Add(7)17 fmt.Println("set1 is ", set1)18 fmt.Println("set2 is ", set2)19 fmt.Println("set1 is subset of set2 ", set1.IsSubset(set2))20 fmt.Println("set2 is subset of set1 ", set2.IsSubset(set1))21 fmt.Println("set1 is superset of set2 ", set1.IsSuperset(set2))22 fmt.Println("set2 is superset of set1 ", set2.IsSuperset(set1))23 fmt.Println("set1 is proper subset of set2 ", set1.IsProperSubset(set2))24 fmt.Println("set2 is proper subset of set1 ", set2.IsProperSubset(set1))25 fmt.Println("set1 is proper superset of set2 ", set1.IsProperSuperset(set2))26 fmt.Println("set2 is proper superset of set1 ", set2.IsProperSuperset(set1))27}28set1 is {1 2 3 4 5 6 7}29set2 is {1 2 3 4 5 6 7}30import (31func main() {32 set1.Add(1)33 set1.Add(2)34 set1.Add(3)
TestOf
Using AI Code Generation
1import (2func main() {3 for i := 0; i < 1000; i++ {4 set.Add(rand.Intn(100000))5 }6 slice := make([]int, 1000)7 for i := 0; i < 1000; i++ {8 slice[i] = rand.Intn(100000)9 }10 intersection := set.TestOf(slice)11 fmt.Println(intersection)12}
TestOf
Using AI Code Generation
1import "fmt"2import "github.com/rahul2k2/set"3func main() {4 set1 := set.NewSet()5 set1.Add(1)6 set1.Add(2)7 set1.Add(3)8 set1.Add(4)9 set1.Add(5)10 set1.Add(6)11 set1.Add(7)12 set1.Add(8)13 set1.Add(9)14 set1.Add(10)15 set2 := set.NewSet()16 set2.Add(1)17 set2.Add(2)18 set2.Add(3)19 set2.Add(4)20 set2.Add(5)21 set2.Add(6)22 set2.Add(7)23 set2.Add(8)24 set2.Add(9)25 set2.Add(10)26 set3 := set.NewSet()27 set3.Add(1)28 set3.Add(2)29 set3.Add(3)30 set3.Add(4)31 set3.Add(5)32 set3.Add(6)33 set3.Add(7)34 set3.Add(8)35 set3.Add(9)36 set3.Add(10)37 set4 := set.NewSet()38 set4.Add(1)39 set4.Add(2)40 set4.Add(3)41 set4.Add(4)42 set4.Add(5)43 set4.Add(6)44 set4.Add(7)45 set4.Add(8)46 set4.Add(9)47 set4.Add(10)48 set5 := set.NewSet()49 set5.Add(1)50 set5.Add(2)51 set5.Add(3)52 set5.Add(4)53 set5.Add(5)54 set5.Add(6)55 set5.Add(7)56 set5.Add(8)57 set5.Add(9)58 set5.Add(10)59 set6 := set.NewSet()60 set6.Add(1)61 set6.Add(2)62 set6.Add(3)63 set6.Add(4)64 set6.Add(5)65 set6.Add(6)66 set6.Add(7)67 set6.Add(8)68 set6.Add(9)69 set6.Add(10)
TestOf
Using AI Code Generation
1import (2func main() {3 s := set.New()4 s.Add("one")5 s.Add("two")6 s.Add("three")7 fmt.Println(s.TestOf("one"))8 fmt.Println(s.TestOf("four"))9}10import (11func main() {12 s := set.New()13 s.Add("one")14 s.Add("two")15 s.Add("three")16 fmt.Println(s.Size())17}18import (19func main() {20 s := set.New()21 s.Add("one")22 s.Add("two")23 s.Add("three")24 fmt.Println(s.Values())25}26import (27func main() {28 s := set.New()29 s.Add("one")30 s.Add("two")31 s.Add("three")32 fmt.Println(s.Values())33 s.Delete("two")34 fmt.Println(s.Values())35}36import (37func main() {38 s := set.New()39 s.Add("one")40 s.Add("two")41 s.Add("three")42 fmt.Println(s.Values())43 s.Clear()44 fmt.Println(s.Values())45}46import (47func main() {48 s1 := set.New()49 s1.Add("one")50 s1.Add("two")51 s1.Add("three")52 s2 := set.New()53 s2.Add("four
TestOf
Using AI Code Generation
1import (2func main() {3 s := set.New()4 s.Add(1)5 s.Add(2)6 s.Add(3)7 s.Remove(2)8 for element := range s.Iterate() {9 fmt.Println(element)10 }11}12import (13func main() {14 s := set.New()15 s.Add(1)16 s.Add(2)17 s.Add(3)18 s.Remove(2)19 for element := range s.Iterate() {20 fmt.Println(element)21 }22}23import (24func main() {25 s := set.New()26 s.Add(1)27 s.Add(2)28 s.Add(3)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!