[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-75506":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":12,"openIssues":13,"contributorsCount":13,"subscribersCount":13,"size":13,"stars1d":12,"stars7d":14,"stars30d":15,"stars90d":13,"forks30d":13,"starsTrendScore":16,"compositeScore":17,"rankGlobal":9,"rankLanguage":9,"license":18,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":21,"hasPages":19,"topics":22,"createdAt":9,"pushedAt":9,"updatedAt":23,"readmeContent":24,"aiSummary":25,"trendingCount":13,"starSnapshotCount":13,"syncStatus":12,"lastSyncTime":26,"discoverSource":27},75506,"btype","tidwall\u002Fbtype","tidwall","B-tree based collection types for Go",null,"Go",279,2,0,7,188,6,1.43,"MIT License",false,"main",true,[],"2026-06-12 02:03:34","\u003Cp align=\"center\">\n\u003Cpicture>\n  \u003Csource media=\"(prefers-color-scheme: dark)\" srcset=\"\u002F.github\u002Flogo-dark.png\">\n  \u003Csource media=\"(prefers-color-scheme: light)\" srcset=\"\u002F.github\u002Flogo-light.png\">\n  \u003Cimg alt=\"Tile38\" src=\"\u002F.github\u002Fimages\u002Flogo-light.png\" width=\"640\">\n\u003C\u002Fpicture>\n\u003Cbr>\n\u003Ca href=\"#map\">Map\u003C\u002Fa> •\n\u003Ca href=\"#set\">Set\u003C\u002Fa> •\n\u003Ca href=\"#array\">Array\u003C\u002Fa> •\n\u003Ca href=\"#table\">Table\u003C\u002Fa> •\n\u003Ca href=\"#stack\">Stack\u003C\u002Fa> •\n\u003Ca href=\"#queue\">Queue\u003C\u002Fa> • \n\u003Ca href=\"#deque\">Deque\u003C\u002Fa> •\n\u003Ca href=\"#prique\">Prique\u003C\u002Fa>\n\u003Cbr>\n\u003Cbr>\n\u003Ca href=\"https:\u002F\u002Fgodoc.org\u002Fgithub.com\u002Ftidwall\u002Fbtype\"\n>\u003Cimg src=\"https:\u002F\u002Fgodoc.org\u002Fgithub.com\u002Ftidwall\u002Fbtree?status.svg\"\n>\u003C\u002Fa>\n\u003C\u002Fp>\n\nThe btype package provides btree based collection types that allow Go programmers \nto easily implement common data structures like maps, arrays, queues, and stacks. \n\nIt's hand-crafted with performance in mind and is generally faster than the \nstate of the art btrees for Go, Rust, and C++.\n[google\u002Fbtree](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fbtree), \n[tidwall\u002Fbtree](https:\u002F\u002Fgithub.com\u002Ftidwall\u002Fbtree), \n[rust\u002FBTreeMap](https:\u002F\u002Fdoc.rust-lang.org\u002Fstd\u002Fcollections\u002Fstruct.BTreeMap.html), \n[frozenca\u002Fbtree](https:\u002F\u002Fgithub.com\u002Ffrozenca\u002FBTree).\n\u003Csup>[[benchmarks]](#performance)\u003C\u002Fsup>\n\n# Features\n\n- Includes collections types: map, set, queue, stack, table. Each backed by a btree structure.\n- Modern Go ergonomics with a friendly API.\n- All data operations are O(log n) complexity.\n- Instant [copy-on-write](#copy-on-write) (shadow clones), providing O(1) snapshots.\n- Uses [btree counting](https:\u002F\u002Fwww.chiark.greenend.org.uk\u002F~sgtatham\u002Falgorithms\u002Fcbtree.html) for O(log n) random access.\n- Exhaustively tested code with 100% coverage.\n- Optimized for [high performance](#performance) and low memory.\n\n# Types\n\nIncludes the following collection types:\n\n- [`Map`](#map): Key value pairs. Sorting ordered by key\n- [`Set`](#set): Like Map, but only for storing keys. No values\n- [`Array`](#array): Dynamic array of unsorted data\n- [`Table`](#table): Data sorted by key fields or a custom compare function\n- [`Stack`](#stack): LIFO (last-in, first-out) data structure\n- [`Queue`](#queue): FIFO (first-in, first-out) data structure\n- [`Deque`](#deque): Double-ended queue\n- [`Prique`](#prique): Priority queue\n\n\n## Map\n\nbtype.Map is a sorted associative collection of key-value pairs with unique keys. \nThe keys adhere to the parameter type [`cmp.Ordered`](https:\u002F\u002Fpkg.go.dev\u002Fcmp#Ordered) and are naturally sorted using [`cmp.Compare`](https:\u002F\u002Fpkg.go.dev\u002Fcmp#Compare).\n\n### Operations\n\n```py\nInsert(key, val)        # Insert an item. (does not replace if already exists)\nReplace(key, val)       # Replace an existing item. (does not insert if not exists)\nSet(key, val)           # Insert or replace an item.\nGet(key, val)           # Get an existing item.\nContains(key)           # Test if an item exists.\nDelete(key)             # Remove an item.\n\nSeek(key)               # Searches for the first item that is >= to key.\nSeekNext(key)           # Searches for the first item that is > key.\nSeekPrev(key)           # Searches for the first item that is \u003C key.\n\nAll()                   # Iterate items in ascending order.            (iter.Seq2[K,V])\nBackward()              # Iterate items in descending order.           (iter.Seq2[K,V])\nAscend(key)             # Iterate items in ascending order >= to key.  (iter.Seq2[K,V])\nDescend(key)            # Iterate items in descending order \u003C= to key. (iter.Seq2[K,V])\nKeys()                  # Iterate key only in ascending order.         (iter.Seq[K])\nValues()                # Iterate values only in ascending order.      (iter.Seq[K])\nDrain()                 # Iterate and remove in ascending order.       (iter.Seq2[K,V])\nDrainBackward()         # Iterate and remove in descending order.      (iter.Seq2[K,V])\n\nPushFront(key, val)     # Insert item to front of map.\nPushBack(key, val)      # Insert item to back of map.\nPopFront()              # Remove the first item.\nPopBack()               # Remove the last item.\nFront()                 # Get the first item.\nBack()                  # Get the last item.\n\nInsertAt(i, key, val)   # Inserts item at index. (collection size grows by one)\nReplaceAt(i, key, val)  # Replace an item at index.\nGetAt(i)                # Get an item at index.\nIndexOf(key)            # Get the index of an item.\nDeleteAt(i)             # Remove an item at index.\nAscendAt(i)             # Iterate items in ascending order >= to index.  (iter.Seq2[K,V])\nDescendAt(i)            # Iterate items in descending order \u003C= to index. (iter.Seq2[K,V])\n\nDeleteRange(min, max)   # Remove items within the provided sub-range. [min,max)\nDeleteRangeAt(i, count) # Remove items starting at index.\n\nLen()                   # Get the number of items in map.\nCopy()                  # Copy map, fast O(1), uses Copy-on-write shadow cloning.\nClear()                 # Remove all items from map\nRelease()               # Same as Clear() but optimized for copied collections.\n```\n\n### Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com\u002Ftidwall\u002Fbtype\"\n)\n\nfunc main() {\n\t\u002F\u002F Create a map\n\tvar users btype.Map[string, string]\n\n\t\u002F\u002F Add some users\n\tusers.Insert(\"user:4\", \"Andrea\")\n\tusers.Insert(\"user:6\", \"Andy\")\n\tusers.Insert(\"user:2\", \"Andy\")\n\tusers.Insert(\"user:1\", \"Jane\")\n\tusers.Insert(\"user:5\", \"Janet\")\n\tusers.Insert(\"user:3\", \"Steve\")\n\n\t\u002F\u002F Iterate over the map and print each user\n\tfor key, value := range users.All() {\n\t\tfmt.Printf(\"%s %s\\n\", key, value)\n\t}\n\tfmt.Printf(\"\\n\")\n\n\t\u002F\u002F Delete a couple users\n\tusers.Delete(\"user:5\")\n\tusers.Delete(\"user:1\")\n\n\t\u002F\u002F Print the map again\n\tfor key, value := range users.All() {\n\t\tfmt.Printf(\"%s %s\\n\", key, value)\n\t}\n\tfmt.Printf(\"\\n\")\n}\n\n\u002F\u002F Output:\n\u002F\u002F user:1 Jane\n\u002F\u002F user:2 Andy\n\u002F\u002F user:3 Steve\n\u002F\u002F user:4 Andrea\n\u002F\u002F user:5 Janet\n\u002F\u002F user:6 Andy\n\u002F\u002F\n\u002F\u002F user:2 Andy\n\u002F\u002F user:3 Steve\n\u002F\u002F user:4 Andrea\n\u002F\u002F user:6 Andy\n```\n\n## Set\n\nbtype.Set is an associative collection of unique sorted keys. \nThe keys adhere to the parameter type [`cmp.Ordered`](https:\u002F\u002Fpkg.go.dev\u002Fcmp#Ordered) and are naturally sorted using [`cmp.Compare`](https:\u002F\u002Fpkg.go.dev\u002Fcmp#Compare).\n\n### Operations\n\n```py\nInsert(key)             # Insert key.\nContains(key)           # Check if key exists.\nDelete(key)             # Remove key.\nLen()                   # Get the number of keys in the collection.\n\nAll()                   # Iterate keys in ascending order.            (iter.Seq[K])\nBackward()              # Iterate keys in descending order.           (iter.Seq[K])\nAscend(key)             # Iterate keys in ascending order >= to key.  (iter.Seq[K])\nDescend(key)            # Iterate keys in descending order \u003C= to key. (iter.Seq[K])\nDrain()                 # Iterate and remove in ascending order.      (iter.Seq[K])\nDrainBackward()         # Iterate and remove in descending order.     (iter.Seq[K])\n\nSeek(key)               # Searches for the first key that is >= to key.\nSeekNext(key)           # Searches for the first key that is > key.\nSeekPrev(key)           # Searches for the first key that is \u003C key.\n\nPushFront(key)          # Insert key to front of collection.\nPushBack(key)           # Insert key to back of collection.\nPopFront()              # Remove the first key.\nPopBack()               # Remove the last key.\nFront()                 # Get the first key.\nBack()                  # Get the last key.\n\nInsertAt(i, key)        # Insert key at index. (collection size grows by one)\nReplaceAt(i, key)       # Replace key at index.\nGetAt(i)                # Gets key at index.\nIndexOf(key)            # Get the index of key.\nDeleteAt(i)             # Remove key at index.\nAscendAt(i)             # Iterate keys in ascending order >= to index. (iter.Seq[K])\nDescendAt(i)            # Iterate key in descending order \u003C= to index. (iter.Seq[K])\n\nDeleteRange(min, max)   # Remove keys within the provided sub-range. [min,max)\nDeleteRangeAt(i, count) # Remove keys starting at index.\n\nLen()                   # Get the number of items in collection.\nCopy()                  # Copy collection, fast O(1), uses Copy-on-write shadow cloning.\nClear()                 # Remove all items from collection\nRelease()               # Same as Clear() but optimized for copied collections.\n```\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com\u002Ftidwall\u002Fbtype\"\n)\n\nfunc main() {\n\t\u002F\u002F Create a set\n\tvar names btype.Set[string]\n\n\t\u002F\u002F Add some names\n\tnames.Insert(\"Jane\")\n\tnames.Insert(\"Andrea\")\n\tnames.Insert(\"Steve\")\n\tnames.Insert(\"Andy\")\n\tnames.Insert(\"Janet\")\n\tnames.Insert(\"Andy\")\n\n\t\u002F\u002F Iterate over the set and print each name\n\tfor key := range names.All() {\n\t\tfmt.Printf(\"%s\\n\", key)\n\t}\n\tfmt.Printf(\"\\n\")\n\n\t\u002F\u002F Delete a couple names\n\tnames.Delete(\"Steve\")\n\tnames.Delete(\"Andy\")\n\n\t\u002F\u002F Print the names again\n\tfor key := range names.All() {\n\t\tfmt.Printf(\"%s\\n\", key)\n\t}\n\tfmt.Printf(\"\\n\")\n}\n\n\u002F\u002F Output:\n\u002F\u002F Andrea\n\u002F\u002F Andy\n\u002F\u002F Jane\n\u002F\u002F Janet\n\u002F\u002F Steve\n\u002F\u002F\n\u002F\u002F Andrea\n\u002F\u002F Jane\n\u002F\u002F Janet\n```\n\n## Array\n\nbtype.Array is a dynamic resizable array of unsorted items.\nIt provides random access with `O(log n)` complexity to all data operations, \nincluding inserting and deleting items in the middle of the array.\n\n\n### Operations\n\n```py\nInsert(i, item)       # Insert item at index. (collection size grows by one)\nReplace(i, item)      # Replace existing item at index.\nGet(i)                # Gets item at index.\nDelete(i)             # Remove item at index.\n\nAll()                 # Iterate items in ascending order.              (iter.Seq[T])\nBackward()            # Iterate items in descending order.             (iter.Seq[T])\nAscend(i)             # Iterate items in ascending order >= to index.  (iter.Seq[T])\nDescend(i)            # Iterate items in descending order \u003C= to index. (iter.Seq[T])\nDrain()               # Iterate and remove in ascending order.         (iter.Seq[T])\nDrainBackward()       # Iterate and remove in descending order.        (iter.Seq[T])\n\nPushFront(item)       # Insert item to front of collection.\nPushBack(item)        # Insert item to back of collection.\nPopFront()            # Remove the first item.\nPopBack()             # Remove the last item.\nFront()               # Get the first item.\nBack()                # Get the last item.\n\nDeleteRange(i, count) # Remove items starting at index.\n\nLen()                 # Get the number of items in collection.\nCopy()                # Copy collection, fast O(1), uses Copy-on-write shadow cloning.\nClear()               # Remove all items from collection\nRelease()             # Same as Clear() but optimized for copied collections.\n```\n\n### Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com\u002Ftidwall\u002Fbtype\"\n)\n\nfunc main() {\n\t\u002F\u002F Create an array of names\n\tvar names btype.Array[string]\n\n\t\u002F\u002F Add some names\n\tnames.Insert(0, \"Andrea\")\n\tnames.Insert(1, \"Tom\")\n\tnames.Insert(2, \"Andy\")\n\tnames.Insert(3, \"Jane\")\n\tnames.Insert(4, \"Janet\")\n\tnames.Insert(5, \"Steve\")\n\n\t\u002F\u002F Iterate over the array and print each name\n\tfor name := range names.All() {\n\t\tfmt.Printf(\"%s\\n\", name)\n\t}\n\tfmt.Printf(\"\\n\")\n\n\t\u002F\u002F Delete a couple names\n\tnames.Delete(3)\n\tnames.Delete(1)\n\n\t\u002F\u002F Print the names again\n\tfor name := range names.All() {\n\t\tfmt.Printf(\"%s\\n\", name)\n\t}\n\tfmt.Printf(\"\\n\")\n}\n\n\u002F\u002F Output:\n\u002F\u002F Andrea\n\u002F\u002F Tom\n\u002F\u002F Andy\n\u002F\u002F Jane\n\u002F\u002F Janet\n\u002F\u002F Steve\n\u002F\u002F\n\u002F\u002F Andrea\n\u002F\u002F Andy\n\u002F\u002F Janet\n\u002F\u002F Steve\n```\n\n\u003C!----------------------------------------------------------------------------->\n\n## Table\n\nbtype.Table is a general purpose btree collection for storing sorted data.\n\nThis collection type is functionally similar to \n[`tidwall\u002Fbtree.BTreeG`](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Ftidwall\u002Fbtree#BTreeG) and\n[`google\u002Fbtree.BTreeG`](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgoogle\u002Fbtree#BTreeG), \nbut includes additional features and performance enhancements.\n\n### Features\n\n- Automatic type ordering detection.\n- Optional [custom comparator](#custom-comparator)\n- [Tagged struct keys](#tagged-struct-keys) (row-like primary and composite keys)\n\n### Automatic type ordering\n\nA btype.Table will automatically detect the ordering of the data type. \n\n### cmp.Ordered data type\n\nWhen the data type is `cmp.Ordered` then `cmp.Compare` is used to sort the data.\n\n```go\nvar names btype.Table[string]\n\nnames.Insert(\"Andrea\")\nnames.Insert(\"Tom\")\nnames.Insert(\"Andy\")\nnames.Insert(\"Jane\")\nnames.Insert(\"Janet\")\nnames.Insert(\"Steve\")\n\nfor name := range names.All() {\n\tfmt.Printf(\"%s\\n\", name)\n}\n\n\u002F\u002F Output:\n\u002F\u002F Andrea\n\u002F\u002F Andy\n\u002F\u002F Jane\n\u002F\u002F Janet\n\u002F\u002F Steve\n\u002F\u002F Tom\n```\n\n### Struct field detection\n\nWhen the data type is a struct, or pointer to struct, then the data is sorted \nby the first struct field that adheres to `cmp.Ordered`.\n\n```go\ntype User struct {\n\tid   int\n\tname string\n}\n\nvar users btype.Table[User]\nusers.Insert(User{4, \"Andrea\"})\nusers.Insert(User{6, \"Andy\"})\nusers.Insert(User{2, \"Andy\"})\nusers.Insert(User{1, \"Jane\"})\nusers.Insert(User{5, \"Janet\"})\nusers.Insert(User{3, \"Steve\"})\n\nfor user := range users.All() {\n\tfmt.Printf(\"%d %s\\n\", user.id, user.name)\n}\n\n\u002F\u002F Output:\n\u002F\u002F 1 Jane\n\u002F\u002F 2 Andy\n\u002F\u002F 3 Steve\n\u002F\u002F 4 Andrea\n\u002F\u002F 5 Janet\n\u002F\u002F 6 Andy\n```\n\n### Custom comparator\n\nA custom comparator may be used to override automatic detection.\n\n```go\ntype User struct {\n\tage  int\n\tname string\n}\n\n\u002F\u002F sort by name, then age\nusers := btype.NewTableOptions(btype.TableOptions[User]{\n\tCompare: func(a, b User) int {\n\t\tc := cmp.Compare(a.name, b.name)\n\t\tif c == 0 {\n\t\t\tc = cmp.Compare(a.age, b.age)\n\t\t}\n\t\treturn c\n\t},\n})\nusers.Insert(User{27, \"Andrea\"})\nusers.Insert(User{54, \"Andy\"})\nusers.Insert(User{31, \"Andy\"})\nusers.Insert(User{43, \"Jane\"})\nusers.Insert(User{29, \"Janet\"})\nusers.Insert(User{62, \"Steve\"})\n\nfor user := range users.All() {\n\tfmt.Printf(\"%d %s\\n\", user.age, user.name)\n}\n\n\u002F\u002F Output:\n\u002F\u002F 27 Andrea\n\u002F\u002F 31 Andy\n\u002F\u002F 54 Andy\n\u002F\u002F 43 Jane\n\u002F\u002F 29 Janet\n\u002F\u002F 62 Steve\n```\n\n### Tagged struct keys\n\nStructs may include tagged keys, which is a simple and explicit way to\ndefine key order. The syntax resembling a traditional database table.\n\nThe tag `btype:\"key\"` designates that struct field as the key.\n\n```go\n\u002F\u002F Order by id\ntype User struct {\n\tid   int `btype:\"key\"`\n\tname string\n}\n```\n\nA composite key can be made by adding two or more tags.\n\n```go\n\u002F\u002F Order by last, then first\ntype User struct {\n\tlast  string `btype:\"key\"`\n\tfirst string `btype:\"key\"`\n}\n```\n\nBy default, order of the keys are automatic.\nBut it's possible to define the order manually by adding a `.{index}` to the tag.\n\n```go\n\u002F\u002F Order by last, then first\ntype User struct {\n\tfirst string `btype:\"key.1\"`\n\tlast  string `btype:\"key.0\"`\n}\n```\n\nKeys may be ordered ascending or descending using `asc` and `desc`, respectively.\nAscending is the default.\n\n\n```go\n\u002F\u002F Order by last descending, then first ascending\ntype User struct {\n\tlast  string `btype:\"key,desc\"`\n\tfirst string `btype:\"key,asc\"`\n}\n```\n\nText collation may be added to string keys.\n\n```go\n\u002F\u002F Use case-insensitive binary collation.\n\u002F\u002F Order by last descending, then first ascending.\ntype User struct {\n \tlast  string `btype:\"key,binary_CI,desc\"`\n \tfirst string `btype:\"key,binary_CI\"`\n}\n```\n\nAvailable collations:\n\n- `binary_CS`: Case sensitive binary strings (default)\n- `binary_CI`: Case insensitive binary strings\n- `utf8_CS`: Case sensitive utf8 unicode\n- `utf8_CI`: Case insensitive utf8 unicode\n\nAlso `bin_CS`, `CS`, `bin_CI`, and `CI` are available as shorthand for \n`binary_CS` and `binary_CI`.\n\nMore collations may be added in the future.\n\n### Operations\n\nTable operations include:\n\n```py\nInsert(item)            # Insert an item. (does not replace if already exists)\nReplace(item)           # Replace an existing item. (does not insert if not exists)\nSet(item)               # Insert or replace an item.\nGet(key)                # Get an existing item.\nContains(key)           # Test if an item exists.\nDelete(key)             # Remove an item.\n\nSeek(key)               # Searches for the first item that is >= to key.\nSeekNext(key)           # Searches for the first item that is > key.\nSeekPrev(key)           # Searches for the first item that is \u003C key.\n\nAll()                   # Iterate items in ascending order.            (iter.Seq[T])\nBackward()              # Iterate items in descending order.           (iter.Seq[T])\nAscend(key)             # Iterate items in ascending order >= to key.  (iter.Seq[T])\nDescend(key)            # Iterate items in descending order \u003C= to key. (iter.Seq[T])\nDrain()                 # Iterate and remove in ascending order.       (iter.Seq[T])\nDrainBackward()         # Iterate and remove in descending order.      (iter.Seq[T])\n\nPushFront(item)         # Insert item to front of table.\nPushBack(item)          # Insert item to back of table.\nPopFront()              # Remove the first item.\nPopBack()               # Remove the last item.\nFront()                 # Get the first item.\nBack()                  # Get the last item.\n\nInsertAt(i, item)       # Inserts item at index. (collection size grows by one)\nReplaceAt(i, item)      # Replace an item at index.\nGetAt(i)                # Get an item at index.\nIndexOf(key)            # Get the index of an item.\nDeleteAt(i)             # Remove an item at index.\nAscendAt(i)             # Iterate items in ascending order >= to index.  (iter.Seq[T])\nDescendAt(i)            # Iterate items in descending order \u003C= to index. (iter.Seq[T])\n\nDeleteRange(min, max)   # Remove items within the provided sub-range. [min,max)\nDeleteRangeAt(i, count) # Remove items starting at index.\n\nLen()                   # Get the number of items in collection.\nCopy()                  # Copy collection, fast O(1), uses Copy-on-write shadow cloning.\nClear()                 # Remove all items from collection\nRelease()               # Same as Clear() but optimized for copied collections.\n```\n\n\u003C!----------------------------------------------------------------------------->\n\n## Stack\n\nbtype.Stack is a collection with the functionality of a stack - specifically, \na LIFO (last-in, first-out) data structure.\n\n### Operations\n\n```py\nPush(item) # Insert item to top of stack.\nPop()      # Remove item from top stack.\nTop()      # Get the top item in stack\n\nAll()      # Iterate items in ascending order.      (iter.Seq[T])\nDrain()    # Iterate and remove in ascending order. (iter.Seq[T])\n\nLen()      # Get the number of items in collection.\nCopy()     # Copy collection, fast O(1), uses Copy-on-write shadow cloning.\nClear()    # Remove all items from collection\nRelease()  # Same as Clear() but optimized for copied collections.\n```\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com\u002Ftidwall\u002Fbtype\"\n)\n\nfunc main() {\n\t\u002F\u002F Create an stack of names\n\tvar names btype.Stack[string]\n\n\t\u002F\u002F Add some names\n\tnames.Push(\"Andrea\")\n\tnames.Push(\"Tom\")\n\tnames.Push(\"Andy\")\n\tnames.Push(\"Jane\")\n\tnames.Push(\"Janet\")\n\tnames.Push(\"Steve\")\n\n\t\u002F\u002F Iterate over the stack and print each name\n\tfor name := range names.All() {\n\t\tfmt.Printf(\"%s\\n\", name)\n\t}\n\tfmt.Printf(\"\\n\")\n\n\t\u002F\u002F Pop a the top two names\n\tvar name string\n\tname, _ = names.Pop()\n\tfmt.Printf(\"%s\\n\", name)\n\tname, _ = names.Pop()\n\tfmt.Printf(\"%s\\n\", name)\n\tfmt.Printf(\"\\n\")\n\n\t\u002F\u002F Print the names again\n\tfor name := range names.All() {\n\t\tfmt.Printf(\"%s\\n\", name)\n\t}\n\tfmt.Printf(\"\\n\")\n}\n\n\u002F\u002F Output:\n\u002F\u002F Steve\n\u002F\u002F Janet\n\u002F\u002F Jane\n\u002F\u002F Andy\n\u002F\u002F Tom\n\u002F\u002F Andrea\n\u002F\u002F\n\u002F\u002F Steve\n\u002F\u002F Janet\n\u002F\u002F\n\u002F\u002F Jane\n\u002F\u002F Andy\n\u002F\u002F Tom\n\u002F\u002F Andrea\n```\n\n## Queue\n\nbtype.Queue is a collection with the functionality of a queue - specifically, \na FIFO (first-in, first-out) data structure.\n\n### Operations\n\n```py\nPush(item) # Insert item at the end of queue.\nPop()      # Remove the first item.\nFront()    # Get the first item.\n\nAll()      # Iterate items in ascending order.      (iter.Seq[T])\nDrain()    # Iterate and remove in ascending order. (iter.Seq[T])\n\nLen()      # Get the number of items in collection.\nCopy()     # Copy collection, fast O(1), uses Copy-on-write shadow cloning.\nClear()    # Remove all items from collection\nRelease()  # Same as Clear() but optimized for copied collections.\n```\n\n### Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com\u002Ftidwall\u002Fbtype\"\n)\n\nfunc main() {\n\t\u002F\u002F Create an queue of names\n\tvar names btype.Queue[string]\n\n\t\u002F\u002F Add some names\n\tnames.Push(\"Andrea\")\n\tnames.Push(\"Tom\")\n\tnames.Push(\"Andy\")\n\tnames.Push(\"Jane\")\n\tnames.Push(\"Janet\")\n\tnames.Push(\"Steve\")\n\n\t\u002F\u002F Iterate over the array and print each name\n\tfor name := range names.All() {\n\t\tfmt.Printf(\"%s\\n\", name)\n\t}\n\tfmt.Printf(\"\\n\")\n\n\t\u002F\u002F Pop the first two names\n\tvar name string\n\tname, _ = names.Pop()\n\tfmt.Printf(\"%s\\n\", name)\n\tname, _ = names.Pop()\n\tfmt.Printf(\"%s\\n\", name)\n\tfmt.Printf(\"\\n\")\n\n\t\u002F\u002F Print the names again\n\tfor name := range names.All() {\n\t\tfmt.Printf(\"%s\\n\", name)\n\t}\n\tfmt.Printf(\"\\n\")\n}\n\n\u002F\u002F Output:\n\u002F\u002F Andrea\n\u002F\u002F Tom\n\u002F\u002F Andy\n\u002F\u002F Jane\n\u002F\u002F Janet\n\u002F\u002F Steve\n\u002F\u002F\n\u002F\u002F Andrea\n\u002F\u002F Tom\n\u002F\u002F\n\u002F\u002F Andy\n\u002F\u002F Jane\n\u002F\u002F Janet\n\u002F\u002F Steve\n```\n\n## Deque\n\nbtype.Deque is a double-ended queue.\n\n### Operations\n\n```py\nPush(item)      # Insert item at the end of queue.\nPopFront()      # Remove the first item.\nPopBack()       # Remove the last item.\nFront()         # Get the first item.\nBack( )         # Get the last item.\n\nAll()           # Iterate items in ascending order.       (iter.Seq[T])\nBackward()      # Iterate items in desending order.       (iter.Seq[T])\nDrain()         # Iterate and remove in ascending order.  (iter.Seq[T])\nDrainBackward() # Iterate and remove in descending order. (iter.Seq[T])\n\nLen()           # Get the number of items in collection.\nCopy()          # Copy collection, fast O(1), uses Copy-on-write shadow cloning.\nClear()         # Remove all items from collection\nRelease()       # Same as Clear() but optimized for copied collections.\n```\n\n### Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com\u002Ftidwall\u002Fbtype\"\n)\n\nfunc main() {\n\t\u002F\u002F Create an queue of names\n\tvar names btype.Deque[string]\n\n\t\u002F\u002F Add some names\n\tnames.PushFront(\"Andrea\")\n\tnames.PushBack(\"Tom\")\n\tnames.PushFront(\"Andy\")\n\tnames.PushBack(\"Jane\")\n\tnames.PushFront(\"Janet\")\n\tnames.PushBack(\"Steve\")\n\n\t\u002F\u002F Iterate over the array and print each name\n\tfor name := range names.All() {\n\t\tfmt.Printf(\"%s\\n\", name)\n\t}\n\tfmt.Printf(\"\\n\")\n\n\t\u002F\u002F Pop the first two names\n\tvar name string\n\tname, _ = names.PopFront()\n\tfmt.Printf(\"%s\\n\", name)\n\tname, _ = names.PopBack()\n\tfmt.Printf(\"%s\\n\", name)\n\tfmt.Printf(\"\\n\")\n\n\t\u002F\u002F Print the names again\n\tfor name := range names.All() {\n\t\tfmt.Printf(\"%s\\n\", name)\n\t}\n\tfmt.Printf(\"\\n\")\n}\n\n\u002F\u002F Output:\n\u002F\u002F Janet\n\u002F\u002F Andy\n\u002F\u002F Andrea\n\u002F\u002F Tom\n\u002F\u002F Jane\n\u002F\u002F Steve\n\u002F\u002F\n\u002F\u002F Janet\n\u002F\u002F Steve\n\u002F\u002F\n\u002F\u002F Andy\n\u002F\u002F Andrea\n\u002F\u002F Tom\n\u002F\u002F Jane\n```\n\n## Prique\n\nbtype.Prique is a priority queue collection that sorts items by largest to \nsmallest. Data operations, such as Push() and Pop(), are O(log n).\n\nThis collection has support for duplicate items.\nIt also inherits the [Table](#table) collection, allowing for \n[Tagged struct keys](#tagged-struct-keys).\n\n### Operations\n\n```py\nPush(item) # Insert item into queue.\nPop()      # Remove the largest item.\nFront()    # Get the largest item.\n\nAll()      # Iterate items in order of largest to smallest.      (iter.Seq[T])\nDrain()    # Iterate and remove in order of largest to smallest. (iter.Seq[T])\n\nLen()      # Get the number of items in collection.\nCopy()     # Copy collection, fast O(1), uses Copy-on-write shadow cloning.\nClear()    # Remove all items from collection\nRelease()  # Same as Clear() but optimized for copied collections.\n```\n\n### Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com\u002Ftidwall\u002Fbtype\"\n)\n\nfunc main() {\n\n\ttype User struct {\n\t\tage  int `btype:\"key\"`\n\t\tname string\n\t}\n\n\t\u002F\u002F Create an queue of users\n\tvar users btype.Prique[User]\n\n\t\u002F\u002F Add some names\n\tusers.Push(User{27, \"Andrea\"})\n\tusers.Push(User{54, \"Tom\"})\n\tusers.Push(User{31, \"Andy\"})\n\tusers.Push(User{43, \"Jane\"})\n\tusers.Push(User{29, \"Janet\"})\n\tusers.Push(User{62, \"Steve\"})\n\tusers.Push(User{31, \"Morton\"})\n\n\t\u002F\u002F Iterate over the array and print each name\n\tfor user := range users.All() {\n\t\tfmt.Printf(\"%v %v\\n\", user.name, user.age)\n\t}\n\tfmt.Printf(\"\\n\")\n\n\t\u002F\u002F Pop the first two names\n\tvar user User\n\tuser, _ = users.Pop()\n\tfmt.Printf(\"%v %v\\n\", user.name, user.age)\n\tuser, _ = users.Pop()\n\tfmt.Printf(\"%v %v\\n\", user.name, user.age)\n\tfmt.Printf(\"\\n\")\n\n\t\u002F\u002F Print the names again\n\tfor user := range users.All() {\n\t\tfmt.Printf(\"%v %v\\n\", user.name, user.age)\n\t}\n\tfmt.Printf(\"\\n\")\n}\n\n\u002F\u002F Output:\n\u002F\u002F Steve 62\n\u002F\u002F Tom 54\n\u002F\u002F Jane 43\n\u002F\u002F Morton 31\n\u002F\u002F Andy 31\n\u002F\u002F Janet 29\n\u002F\u002F Andrea 27\n\u002F\u002F \n\u002F\u002F Steve 62\n\u002F\u002F Tom 54\n\u002F\u002F \n\u002F\u002F Jane 43\n\u002F\u002F Morton 31\n\u002F\u002F Andy 31\n\u002F\u002F Janet 29\n\u002F\u002F Andrea 27\n```\n\n## Performance\n\nThe btype package has various optimizations that enhance performance over existing implementations.\n\n- Branch node counting.\n- Auto-detected search method.\n- Seperate keys and values for maps.\n- Prefixing in branch nodes for string keys.\n- Last-first search algo. (fast bounds check, fewer conditions, fast bulk loads)\n- Reference counted COW.\n\n### Benchmarks\n\nhttps:\u002F\u002Fgithub.com\u002Ftidwall\u002Fbtype-bench\n\n- CPU: Ryzen 9 5950X 16-Core Processor\n- Go: go version go1.26.0 linux\u002Famd64\n- Rust: rustc 1.95.0 (59807616e 2026-04-14)\n- C: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0\n- C++: g++ (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0\n\n### Implementations\n\n- [tidwall\u002Fbtype](https:\u002F\u002Fgithub.com\u002Ftidwall\u002Fbtype) Go\n- [google\u002Fbtree](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fbtree) Go\n- [tidwall\u002Fbtree](https:\u002F\u002Fgithub.com\u002Ftidwall\u002Fbtree) Go\n- [rust\u002FBTreeMap](https:\u002F\u002Fdoc.rust-lang.org\u002Fstd\u002Fcollections\u002Fstruct.BTreeMap.html) Rust\n- [tidwall\u002Fbgen](https:\u002F\u002Fgithub.com\u002Ftidwall\u002Fbgen) C\n- [frozenca\u002Fbtree](https:\u002F\u002Fgithub.com\u002Ffrozenca\u002FBTree) C++\n\nBenchmarking 1,000,000 items, 50 runs, taking the average result.\n\n### int32 keys\n\n```\ntidwall\u002Fbtype\ninsert(seq)      1,000,000 ops in   0.017 secs   17.1 ns\u002Fop   58,389,383 op\u002Fsec\ninsert(rand)     1,000,000 ops in   0.076 secs   76.0 ns\u002Fop   13,159,734 op\u002Fsec\nget(seq)         1,000,000 ops in   0.030 secs   29.8 ns\u002Fop   33,599,978 op\u002Fsec\nget(rand)        1,000,000 ops in   0.064 secs   64.4 ns\u002Fop   15,535,343 op\u002Fsec\n\ntidwall\u002Fbtree\ninsert(seq)      1,000,000 ops in   0.037 secs   36.9 ns\u002Fop   27,104,762 op\u002Fsec\ninsert(rand)     1,000,000 ops in   0.134 secs  134.3 ns\u002Fop    7,445,864 op\u002Fsec\nget(seq)         1,000,000 ops in   0.041 secs   41.4 ns\u002Fop   24,141,559 op\u002Fsec\nget(rand)        1,000,000 ops in   0.128 secs  127.9 ns\u002Fop    7,817,200 op\u002Fsec\n\ngoogle\u002Fbtree\ninsert(seq)      1,000,000 ops in   0.070 secs   69.8 ns\u002Fop   14,321,709 op\u002Fsec\ninsert(rand)     1,000,000 ops in   0.153 secs  153.4 ns\u002Fop    6,518,280 op\u002Fsec\nget(seq)         1,000,000 ops in   0.065 secs   64.6 ns\u002Fop   15,486,010 op\u002Fsec\nget(rand)        1,000,000 ops in   0.155 secs  154.9 ns\u002Fop    6,454,916 op\u002Fsec\n\nrust\u002Fbtree\ninsert(seq)      1,000,000 ops in   0.051 secs   51.0 ns\u002Fop   19,624,389 op\u002Fsec\ninsert(rand)     1,000,000 ops in   0.098 secs   98.2 ns\u002Fop   10,187,241 op\u002Fsec\nget(seq)         1,000,000 ops in   0.033 secs   32.6 ns\u002Fop   30,650,401 op\u002Fsec\nget(rand)        1,000,000 ops in   0.097 secs   97.0 ns\u002Fop   10,308,321 op\u002Fsec\n\ntidwall\u002Fbgen\ninsert(seq)      1,000,000 ops in   0.053 secs   52.6 ns\u002Fop   19,011,130 op\u002Fsec\ninsert(rand)     1,000,000 ops in   0.076 secs   75.8 ns\u002Fop   13,186,500 op\u002Fsec\nget(seq)         1,000,000 ops in   0.033 secs   33.0 ns\u002Fop   30,264,262 op\u002Fsec\nget(rand)        1,000,000 ops in   0.069 secs   68.9 ns\u002Fop   14,524,288 op\u002Fsec\n\nfrozenca\u002Fbtree\ninsert(seq)      1,000,000 ops in   0.093 secs   92.7 ns\u002Fop   10,782,702 op\u002Fsec\ninsert(rand)     1,000,000 ops in   0.081 secs   81.5 ns\u002Fop   12,275,940 op\u002Fsec\nget(seq)         1,000,000 ops in   0.044 secs   44.2 ns\u002Fop   22,636,693 op\u002Fsec\nget(rand)        1,000,000 ops in   0.079 secs   79.1 ns\u002Fop   12,638,367 op\u002Fsec\n```\n\n### uint64 keys\n\n```\ntidwall\u002Fbtype\ninsert(seq)      1,000,000 ops in   0.018 secs   18.3 ns\u002Fop   54,498,410 op\u002Fsec\ninsert(rand)     1,000,000 ops in   0.080 secs   80.3 ns\u002Fop   12,457,898 op\u002Fsec\nget(seq)         1,000,000 ops in   0.030 secs   30.1 ns\u002Fop   33,200,724 op\u002Fsec\nget(rand)        1,000,000 ops in   0.072 secs   72.4 ns\u002Fop   13,819,949 op\u002Fsec\n\ntidwall\u002Fbtree\ninsert(seq)      1,000,000 ops in   0.039 secs   38.7 ns\u002Fop   25,824,082 op\u002Fsec\ninsert(rand)     1,000,000 ops in   0.146 secs  146.0 ns\u002Fop    6,849,574 op\u002Fsec\nget(seq)         1,000,000 ops in   0.053 secs   52.6 ns\u002Fop   19,010,440 op\u002Fsec\nget(rand)        1,000,000 ops in   0.141 secs  140.9 ns\u002Fop    7,099,716 op\u002Fsec\n\ngoogle\u002Fbtree\ninsert(seq)      1,000,000 ops in   0.077 secs   76.8 ns\u002Fop   13,028,686 op\u002Fsec\ninsert(rand)     1,000,000 ops in   0.173 secs  172.9 ns\u002Fop    5,784,271 op\u002Fsec\nget(seq)         1,000,000 ops in   0.062 secs   61.9 ns\u002Fop   16,165,628 op\u002Fsec\nget(rand)        1,000,000 ops in   0.166 secs  166.4 ns\u002Fop    6,008,125 op\u002Fsec\n\nrust\u002Fbtree\ninsert(seq)      1,000,000 ops in   0.044 secs   43.6 ns\u002Fop   22,936,305 op\u002Fsec\ninsert(rand)     1,000,000 ops in   0.105 secs  105.2 ns\u002Fop    9,502,632 op\u002Fsec\nget(seq)         1,000,000 ops in   0.034 secs   33.9 ns\u002Fop   29,509,841 op\u002Fsec\nget(rand)        1,000,000 ops in   0.107 secs  106.8 ns\u002Fop    9,362,769 op\u002Fsec\n\ntidwall\u002Fbgen\ninsert(seq)      1,000,000 ops in   0.054 secs   53.7 ns\u002Fop   18,605,963 op\u002Fsec\ninsert(rand)     1,000,000 ops in   0.081 secs   80.6 ns\u002Fop   12,406,050 op\u002Fsec\nget(seq)         1,000,000 ops in   0.033 secs   32.6 ns\u002Fop   30,657,821 op\u002Fsec\nget(rand)        1,000,000 ops in   0.075 secs   75.4 ns\u002Fop   13,269,668 op\u002Fsec\n\nfrozenca\u002Fbtree\ninsert(seq)      1,000,000 ops in   0.094 secs   93.7 ns\u002Fop   10,668,965 op\u002Fsec\ninsert(rand)     1,000,000 ops in   0.094 secs   93.6 ns\u002Fop   10,688,826 op\u002Fsec\nget(seq)         1,000,000 ops in   0.044 secs   43.5 ns\u002Fop   22,964,359 op\u002Fsec\nget(rand)        1,000,000 ops in   0.087 secs   87.0 ns\u002Fop   11,497,710 op\u002Fsec\n```\n\n### string keys\n\n```\ntidwall\u002Fbtype\ninsert(seq)      1,000,000 ops in   0.074 secs   73.9 ns\u002Fop   13,534,682 op\u002Fsec\ninsert(rand)     1,000,000 ops in   0.287 secs  287.2 ns\u002Fop    3,482,420 op\u002Fsec\nget(seq)         1,000,000 ops in   0.094 secs   93.6 ns\u002Fop   10,683,081 op\u002Fsec\nget(rand)        1,000,000 ops in   0.328 secs  327.6 ns\u002Fop    3,052,945 op\u002Fsec\n\ntidwall\u002Fbtree\ninsert(seq)      1,000,000 ops in   0.124 secs  124.3 ns\u002Fop    8,043,933 op\u002Fsec\ninsert(rand)     1,000,000 ops in   0.402 secs  402.3 ns\u002Fop    2,485,505 op\u002Fsec\nget(seq)         1,000,000 ops in   0.122 secs  122.4 ns\u002Fop    8,171,636 op\u002Fsec\nget(rand)        1,000,000 ops in   0.452 secs  452.0 ns\u002Fop    2,212,330 op\u002Fsec\n\ngoogle\u002Fbtree\ninsert(seq)      1,000,000 ops in   0.191 secs  191.0 ns\u002Fop    5,234,886 op\u002Fsec\ninsert(rand)     1,000,000 ops in   0.437 secs  437.3 ns\u002Fop    2,286,980 op\u002Fsec\nget(seq)         1,000,000 ops in   0.146 secs  145.9 ns\u002Fop    6,855,693 op\u002Fsec\nget(rand)        1,000,000 ops in   0.487 secs  487.0 ns\u002Fop    2,053,473 op\u002Fsec\n\nrust\u002Fbtree\ninsert(seq)      1,000,000 ops in   0.250 secs  250.3 ns\u002Fop    3,995,141 op\u002Fsec\ninsert(rand)     1,000,000 ops in   0.510 secs  510.3 ns\u002Fop    1,959,504 op\u002Fsec\nget(seq)         1,000,000 ops in   0.218 secs  218.3 ns\u002Fop    4,581,355 op\u002Fsec\nget(rand)        1,000,000 ops in   0.591 secs  591.0 ns\u002Fop    1,692,138 op\u002Fsec\n\ntidwall\u002Fbgen\ninsert(seq)      1,000,000 ops in   0.392 secs  392.3 ns\u002Fop    2,549,279 op\u002Fsec\ninsert(rand)     1,000,000 ops in   0.400 secs  400.5 ns\u002Fop    2,496,899 op\u002Fsec\nget(seq)         1,000,000 ops in   0.466 secs  466.3 ns\u002Fop    2,144,526 op\u002Fsec\nget(rand)        1,000,000 ops in   0.478 secs  477.6 ns\u002Fop    2,093,912 op\u002Fsec\n\nfrozenca\u002Fbtree\ninsert(seq)      1,000,000 ops in   0.636 secs  636.3 ns\u002Fop    1,571,476 op\u002Fsec\ninsert(rand)     1,000,000 ops in   0.633 secs  632.7 ns\u002Fop    1,580,596 op\u002Fsec\nget(seq)         1,000,000 ops in   0.376 secs  376.5 ns\u002Fop    2,656,345 op\u002Fsec\nget(rand)        1,000,000 ops in   0.618 secs  618.4 ns\u002Fop    1,617,120 op\u002Fsec\n```\n","tidwall\u002Fbtype 是一个为 Go 语言提供的基于 B-树的数据结构集合库。它支持多种常用数据结构，包括 Map、Set、Array、Table、Stack、Queue、Deque 和 Prique，每种数据结构都由高效的 B-树结构支持。该库注重性能优化，相较于同类实现具有更快的执行速度，并且所有操作的时间复杂度均为 O(log n)。此外，btype 还提供了即时的写时复制功能，使得快照创建只需 O(1) 的时间复杂度。通过采用 B-树计数技术，实现了 O(log n) 的随机访问效率。此项目适用于需要高效数据存储和检索的应用场景，特别是对内存使用和性能有较高要求的情况。","2026-06-11 03:52:58","CREATED_QUERY"]