{"id":28000747,"url":"https://github.com/sysprog21/dict","last_synced_at":"2026-02-25T16:02:52.603Z","repository":{"id":55040590,"uuid":"150854681","full_name":"sysprog21/dict","owner":"sysprog21","description":"Ternary Search Tree + Bloom filter","archived":false,"fork":false,"pushed_at":"2021-01-13T15:59:41.000Z","size":2568,"stargazers_count":19,"open_issues_count":1,"forks_count":106,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-08T23:54:37.718Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sysprog21.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-29T10:46:42.000Z","updated_at":"2024-12-16T07:46:34.000Z","dependencies_parsed_at":"2022-08-14T09:50:45.444Z","dependency_job_id":null,"html_url":"https://github.com/sysprog21/dict","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sysprog21/dict","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysprog21%2Fdict","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysprog21%2Fdict/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysprog21%2Fdict/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysprog21%2Fdict/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sysprog21","download_url":"https://codeload.github.com/sysprog21/dict/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysprog21%2Fdict/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29829408,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-25T15:41:19.027Z","status":"ssl_error","status_checked_at":"2026-02-25T15:40:47.150Z","response_time":61,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-08T23:54:33.540Z","updated_at":"2026-02-25T16:02:52.588Z","avatar_url":"https://github.com/sysprog21.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ternary Search Tree (tst)\n\nA ternary search tree is a binary search tree (bst) with an additional\nnode pointer.\n\nThere is a relative dearth of information available about ternary trees,\nand specifially, proper node-rotation when a node is deleted from the tree.\nThe only examples for a node-delete found are simple deletes that leave the\ntree dirty by leaving a node, with or withoutsiblings, but having no valid\nmiddle (or equal) pointer.\n\nWith a binary search tree each node contains a *left* and *right* node-pointer\nso a binary choice controls traversal. Either a *greater than* or *less than*\nchoice. As the result of a comparison between the node-data and a reference\neither the left or right node-pointer is used to further descend.\n\nA ternary search tree adds a third (or middle) node. While you can still use\nthe `left-middle-right` notation, ternary trees use a `low-equal-high` pointer\nverbiage. With each node holding a *key ID*, the node pointers for the this\ncode uses a `lokid`, `eqkid`, and `hikid` pointer naming convention. If the\ndifference between a refernence and the node key is negative (lower than),\nthe `lokid` node is traversed, if they are equal, the `eqkid` node is followed\nor `hikid` is followed.\n\nIn addition to the `node-\u003ekey`, the node used in this example adds a\n*reference count* (a `node-\u003erefcnt`) to the node data to track the number of\noccurrances for each word it holds. So for example, if using the tree to track\nthe words in an editor buffer (where there may be multiple occurrences of 'the'\nor other common words), the node holding 'the' is not deleted, upon delete,\nuntil no other occurrences remain (i.e. the `node-\u003erefcnt` is zero).\n\nEach individual node has the following form:\n```\n                              o\n                              |-key\n                              |-refcnt\n                  ------------+------------\n                  |lokid      |eqkid      |hikid\n                  o           o           o\n```\n\nThe string data (a pointer to a word, or a copy of the word itself) is stored\nin an additional special node following the node containing the last\ncharacter (`node-\u003ekey`) in the search path for the word, cast to type\n(node *) and stored as the `node-\u003eeqkid` pointer. Further, since this is\nthe *node after the last character*, its key is the\n*nul-character* (decimal `0`) just as you would expect when ending a string.\nThus, the 'key's for each of the nodes that make up the search path of a word,\nare the letters in the word with the final node having a key `0` with either\na pointer to the string (if stored in an external data structure) or an\nallocated copy of the string itself if the string is to be stored in the\ntree. (as in holding the words for an edit buffer, where the location/address\nfor the string changes with each keypress). In either case, the traversal down\nnodes to the final node will have a form similar to the following for the word\n\"cat\":\n```\n                              o\n                              |-c\n                              |-0\n                  ------------+------------\n                  |lokid      |eqkid      |hikid\n                  o           o           o\n                              |-a\n                              |-0\n                          ----+----\n                          |   |   |    note: any of the lokid or hikid nodes\n                              o              can also have pointers to nodes\n                              |-t            for words that \"cat\" or \"ca\" is\n                              |-0            a partial prefix to.\n                          ----+----\n                          |   |   |\n                              o\n                              |-0\n                              |-1    \u003c== the refcnt is only relevant to the final node\n                          ----+----\n                          |   |   |\n                        NULL  o  NULL\n                            \"cat\"\n```\n\nThe ternary tree has the same O(n) efficiency for insert and search as does\na bst. The delete is only slightly worse due to the proper deletion of the\nchain of unique nodes that make a word and proper rotation to eliminate the\nfinal node containing siblings. Lookup times associated with loading the\nentire `/usr/share/dict/words` file and searching range between\n`0.000002 - 0.000014` sec. However, the *prefix search* ability offered by\nthe ternary search tree sets it apart from virtually all other data\nstuctures. While Tri/Radix trees can perform as well, their memory\nrequirements are often 20 times more than a ternary tree.\n\nThe benefit of a ternary tree for prefix searching of text lies in its\nability to quickly traverse a tree of any size finding the node containing\nthe last character in the wanted prefix. An in-order traversal of that node\nidentifies all strings in the tree containing the prefix.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsysprog21%2Fdict","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsysprog21%2Fdict","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsysprog21%2Fdict/lists"}