@@ -98,11 +98,6 @@ const (
98
98
PageBodySize = PageSize - PageHeaderSize
99
99
)
100
100
101
- //type Page struct { // to create a pagesize memory without malloc()
102
- // header PageHeader
103
- // body [PageBodySize]byte
104
- //}
105
-
106
101
type LeafPage struct {
107
102
header * PageHeader
108
103
body * LeafPageBody
@@ -135,7 +130,7 @@ type LeafPageCell struct {
135
130
}
136
131
137
132
type InternalPageCell struct {
138
- value uint32_t //pageNum
133
+ value uint32_t //pageNum
139
134
key uint32_t
140
135
}
141
136
@@ -378,9 +373,6 @@ func doMetaCommand(inputBuffer *InputBuffer, table *Table) MetaCommandResult {
378
373
return MetaCommandSuccess
379
374
} else if strings .TrimSpace (string (inputBuffer .buffer )) == ".btree" {
380
375
fmt .Println ("Tree:" )
381
- //header, body := table.pager.getPage(0)
382
- //leafPage := LeafPage{header: header, body: (*LeafPageBody)(body)}
383
- //leafPage.printLeafNode()
384
376
table .pager .printTree (0 , 0 )
385
377
return MetaCommandSuccess
386
378
} else if strings .TrimSpace (string (inputBuffer .buffer )) == ".pages" {
@@ -390,29 +382,59 @@ func doMetaCommand(inputBuffer *InputBuffer, table *Table) MetaCommandResult {
390
382
}
391
383
return MetaCommandSuccess
392
384
} else if strings .TrimSpace (string (inputBuffer .buffer )) == ".keys" {
393
- fmt .Println ("keys:" )
394
- for i := uint32_t (0 ); i < table .pager .numPages ; i ++ {
395
- header , body := table .pager .getPage (i )
396
- if header .pageType == PageLeaf {
397
- cells := (* LeafPageBody )(body ).cells
398
- fmt .Println ("leaf page " , i )
399
- for _ , c := range cells {
400
- fmt .Println (c .key )
401
- }
402
- } else if header .pageType == PageInternal {
403
- fmt .Println ("internal page " , i )
404
- cells := (* InternalPageBody )(body ).cells
405
- for _ , c := range cells {
406
- fmt .Println (c .key )
407
- }
408
- }
409
- }
410
- return MetaCommandSuccess
411
- }
385
+ printKeys (table )
386
+ return MetaCommandSuccess
387
+ } else if strings .TrimSpace (string (inputBuffer .buffer )) == ".kvs" {
388
+ printKvs (table )
389
+ return MetaCommandSuccess
390
+ }
412
391
413
392
return MetaCommandUnrecognizedCommand
414
393
}
415
394
395
+ func printKeys (table * Table ) {
396
+ fmt .Println ("keys:" )
397
+ for i := uint32_t (0 ); i < table .pager .numPages ; i ++ {
398
+ header , body := table .pager .getPage (i )
399
+ if header .pageType == PageLeaf {
400
+ cells := (* LeafPageBody )(body ).cells
401
+ fmt .Println ("leaf page " , i )
402
+ for _ , c := range cells {
403
+ fmt .Println (c .key )
404
+ }
405
+ } else if header .pageType == PageInternal {
406
+ fmt .Println ("internal page " , i )
407
+ cells := (* InternalPageBody )(body ).cells
408
+ for _ , c := range cells {
409
+ fmt .Println (c .key )
410
+ }
411
+ }
412
+ }
413
+ }
414
+
415
+ func printKvs (table * Table ) {
416
+ fmt .Println ("keys&values:" )
417
+ for i := uint32_t (0 ); i < table .pager .numPages ; i ++ {
418
+ header , body := table .pager .getPage (i )
419
+ if header .pageType == PageLeaf {
420
+ cells := (* LeafPageBody )(body ).cells
421
+ fmt .Println ("leaf page " , i )
422
+ fmt .Println ("num rows: " , header .numCells )
423
+ for _ , c := range cells {
424
+ fmt .Println (c .key )
425
+ }
426
+ } else if header .pageType == PageInternal {
427
+ fmt .Println ("internal page " , i )
428
+ fmt .Println ("num rows: " , header .numCells )
429
+ fmt .Println ("right child: " , (* InternalPageBody )(body ).rightChild )
430
+ cells := (* InternalPageBody )(body ).cells
431
+ for _ , c := range cells {
432
+ fmt .Println (c .key , c .value )
433
+ }
434
+ }
435
+ }
436
+ }
437
+
416
438
func prepareStatement (inputBuffer * InputBuffer , statement * Statement ) PrepareResult {
417
439
bufferContent := strings .TrimSpace (string (inputBuffer .buffer ))
418
440
if len (bufferContent ) >= 6 {
0 commit comments