node creates a node from a page and associates it with a given parent.
(pgId common.Pgid, parent *node)
| 861 | |
| 862 | // node creates a node from a page and associates it with a given parent. |
| 863 | func (b *Bucket) node(pgId common.Pgid, parent *node) *node { |
| 864 | common.Assert(b.nodes != nil, "nodes map expected") |
| 865 | |
| 866 | // Retrieve node if it's already been created. |
| 867 | if n := b.nodes[pgId]; n != nil { |
| 868 | return n |
| 869 | } |
| 870 | |
| 871 | // Otherwise create a node and cache it. |
| 872 | n := &node{bucket: b, parent: parent} |
| 873 | if parent == nil { |
| 874 | b.rootNode = n |
| 875 | } else { |
| 876 | parent.children = append(parent.children, n) |
| 877 | } |
| 878 | |
| 879 | // Use the inline page if this is an inline bucket. |
| 880 | var p = b.page |
| 881 | if p == nil { |
| 882 | p = b.tx.page(pgId) |
| 883 | } else { |
| 884 | // if p isn't nil, then it's an inline bucket. |
| 885 | // The pgId must be 0 in this case. |
| 886 | common.Verify(func() { |
| 887 | if pgId != 0 { |
| 888 | panic(fmt.Sprintf("assertion failed: The page ID (%d) isn't 0 for an inline bucket", pgId)) |
| 889 | } |
| 890 | }) |
| 891 | } |
| 892 | |
| 893 | // Read the page into the node and cache it. |
| 894 | n.read(p) |
| 895 | b.nodes[pgId] = n |
| 896 | |
| 897 | // Update statistics. |
| 898 | b.tx.stats.IncNodeCount(1) |
| 899 | |
| 900 | return n |
| 901 | } |
| 902 | |
| 903 | // free recursively frees all pages in the bucket. |
| 904 | func (b *Bucket) free() { |
no test coverage detected