{"record":{"id":"0fa82c0375637f52","repo":"emirpasic/gods","slug":"invalid-order-should-be-at-least-3","errorCode":null,"errorMessage":"Invalid order, should be at least 3","messagePattern":"Invalid order, should be at least 3","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"trees/btree/btree.go","lineNumber":61,"sourceCode":"\tEntries  []*Entry[K, V] // Contained keys in node\n\tChildren []*Node[K, V]  // Children nodes\n}\n\n// Entry represents the key-value pair contained within nodes\ntype Entry[K comparable, V any] struct {\n\tKey   K\n\tValue V\n}\n\n// New instantiates a B-tree with the order (maximum number of children) and the built-in comparator for K\nfunc New[K cmp.Ordered, V any](order int) *Tree[K, V] {\n\treturn NewWith[K, V](order, cmp.Compare[K])\n}\n\n// NewWith instantiates a B-tree with the order (maximum number of children) and a custom key comparator.\nfunc NewWith[K comparable, V any](order int, comparator utils.Comparator[K]) *Tree[K, V] {\n\tif order < 3 {\n\t\tpanic(\"Invalid order, should be at least 3\")\n\t}\n\treturn &Tree[K, V]{m: order, Comparator: comparator}\n}\n\n// Put inserts key-value pair node into the tree.\n// If key already exists, then its value is updated with the new value.\n// Key should adhere to the comparator's type assertion, otherwise method panics.\nfunc (tree *Tree[K, V]) Put(key K, value V) {\n\tentry := &Entry[K, V]{Key: key, Value: value}\n\n\tif tree.Root == nil {\n\t\ttree.Root = &Node[K, V]{Entries: []*Entry[K, V]{entry}, Children: []*Node[K, V]{}}\n\t\ttree.size++\n\t\treturn\n\t}\n\n\tif tree.insert(tree.Root, entry) {\n\t\ttree.size++","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/emirpasic/gods/blob/1d83d5ae39fbb0de45a60365791ff1c8b9bae953/trees/btree/btree.go#L43-L79","documentation":"A constructor guard panic raised by btree.NewWith (reachable via btree.New) when the order argument is less than 3. In a B-tree the order m is the maximum number of children per node; a valid tree requires at least 2 children in the root and ⌈m/2⌉ (at least 1) in other non-leaf nodes, so an order of 2 or lower cannot satisfy B-tree invariants and node-splitting logic would break, hence the constructor rejects it up front.","triggerScenarios":"Thrown at trees/btree/btree.go:61 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass an order of at least 3 when calling btree.New / btree.NewWith (in practice values like 3..1024 are typical; Knuth's classic choice is 2*ceil(ln(m)) etc., e.g. order 32 or 64 for disk-backed use).","Validate the order before constructing: if order < 3 { return fmt.Errorf(...) } and surface it to the caller instead of panicking.","Check where the order value comes from (config file, CLI flag, constant) and correct the source of the too-small value."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1d83d5ae39fbb0de45a60365791ff1c8b9bae953","analyzedAt":"2026-09-03T13:39:53.396Z","contentChangedAt":"2026-09-03T13:39:53.396Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}