{"id":309,"date":"2008-03-07T03:24:58","date_gmt":"2008-03-07T07:24:58","guid":{"rendered":"http:\/\/www.rakkar.org\/blog\/?p=309"},"modified":"2008-03-07T03:24:58","modified_gmt":"2008-03-07T07:24:58","slug":"data-structures-for-optimization","status":"publish","type":"post","link":"https:\/\/rakkar.org\/blog\/index.php\/2008\/03\/07\/data-structures-for-optimization\/","title":{"rendered":"Data structures for fun and optimization"},"content":{"rendered":"<p>\t\t\t\tI was updating the <a HREF=\"http:\/\/www.jenkinssoftware.com\/raknet\/manual\/\">manual<\/a> for <a HREF=\"http:\/\/www.jenkinssoftware.com\">RakNet<\/a> and was reminded of how many data structures I&#8217;ve written for it.<\/p>\n<p>From the manual:<\/p>\n<p>DS_BinarySearchTree.h &#8211; <a href=\"http:\/\/en.wikipedia.org\/wiki\/Binary_search_tree\">Binary search tree<\/a>, and an <a href=\"http:\/\/en.wikipedia.org\/wiki\/AVL_tree\">AVL balanced<\/a> binary search tree.<br \/>\n      DS_BPlusTree.h &#8211; <a href=\"http:\/\/en.wikipedia.org\/wiki\/B%2B_tree\">BPlus tree<\/a> for fast lookup, delete, and insert.<br \/>\n      DS_BytePool.h &#8211; Returns data blocks at certain size thresholds to reduce memory fragmentation.<br \/>\n      DS_ByteQueue.h &#8211; A queue specialized for reading and writing bytes.<br \/>\n      DS_Heap.h &#8211; <a href=\"http:\/\/en.wikipedia.org\/wiki\/Heap_%28data_structure%29\">Heap data structure<\/a>, includes both minheap and maxheap.<br \/>\n      DS_HuffmanEncodingTree.h &#8211; <a href=\"http:\/\/en.wikipedia.org\/wiki\/Huffman_coding\">Huffman encoding tree<\/a>, used to find the minimal bitwise representation given a frequency table.<br \/>\n      DS_HuffmanEncodingTreeFactory.h &#8211; Creates instances of the Huffman encoding tree.<br \/>\n      DS_HuffmanEncodingTreeNode.h &#8211; Node in the Huffman encoding tree.<br \/>\n      DS_LinkedList.h &#8211; Standard <a href=\"http:\/\/en.wikipedia.org\/wiki\/Linked_list\">linked list<\/a>.<br \/>\n      DS_List.h &#8211; Dynamic <a href=\"http:\/\/en.wikipedia.org\/wiki\/Array\">array<\/a> (sometimes improperly called a vector). Also doubles as a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Stack_%28data_structure%29\">stack<\/a>.<br \/>\n      DS_Map.h &#8211; (<a href=\"http:\/\/en.wikipedia.org\/wiki\/Associative_array\">Associative array<\/a>) Ordered list with an per-element sort key.<br \/>\n      DS_MemoryPool.h &#8211; Allocate and free reused instances of a fixed size structure, used to reduce memory fragmentation.<br \/>\n      DS_OrderedChannelHeap.h &#8211; Maxheap which returns a node based on the relative weight of the node&#8217;s associated channel. Used for task scheduling with priorities.<br \/>\n      DS_OrderedList.h &#8211; List ordered by an arbitrary key via <a href=\"http:\/\/en.wikipedia.org\/wiki\/Quicksort\">quicksort<\/a>.<br \/>\n      DS_Queue.h &#8211; Standard <a href=\"http:\/\/en.wikipedia.org\/wiki\/Queue_%28data_structure%29\">queue<\/a> implemented with an array<br \/>\n      DS_QueueLinkedList.h &#8211; Standard queue implemented with a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Linked_list\">linked list<\/a><br \/>\n      DS_RangeList.h &#8211; Stores a list of numerical values, and when the values are sequential, represents them as a range rather than individual elements. Useful when storing many values that are usually sequential.<br \/>\n      DS_Table.h &#8211; <a href=\"http:\/\/en.wikipedia.org\/wiki\/Table_%28database%29\">Table<\/a> with columns and rows, and operations on that table.<br \/>\n      DS_Tree.h &#8211; Noncyclic <a href=\"http:\/\/en.wikipedia.org\/wiki\/Graph_%28data_structure%29\">graph<\/a><br \/>\n      DS_WeightedGraph.h &#8211; Graph with weighted edges, used for routing via <a href=\"http:\/\/en.wikipedia.org\/wiki\/Dijkstra%27s_algorithm\">Dijkstra&#8217;s algorithm<\/a><\/p>\n<p>Data structures is one of the few classes in college that has a significant real-world bearing.  It&#8217;s one of the cornerstones of good design and optimization.<\/p>\n<p>A few times I&#8217;ve been asked why I don&#8217;t just use STL.<\/p>\n<p>1. STL can cause linker errors<br \/>\n2. STL uses exceptions.<br \/>\n3. STL doesn&#8217;t have every feature I need.<br \/>\n4. I don&#8217;t know how well STL is optimized, but I know exactly how well my code is optimized.<br \/>\n5. In college I was confused for months before I figured out when people said &#8216;vector&#8217; they meant &#8216;dynamic array.&#8217; It became a pet-peeve of mine.<br \/>\n6. In college I started writing my own data structures before I knew STL existed.  None of my classes ever covered it And once I started I had momentum to keep going.<br \/>\n5. It&#8217;s something I find interesting and enjoy writing.<\/p>\n<p>Aside from STL, of the game companies I&#8217;ve worked at, I&#8217;ve never seen any of them with as sophisticated a set of data structures as what I have in RakNet. When you need to process and track 30,000 messages a second you need heavy duty data structures like my memory-pool optimized B+ tree. Being able to support 30,000 messages vs. your standard game&#8217;s 20-30 messages a second is part of the polish you get with a dedicated mature library.\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was updating the manual for RakNet and was reminded of how many data structures I&#8217;ve written for it. From the manual: DS_BinarySearchTree.h &#8211; Binary search tree, and an AVL balanced binary search tree. DS_BPlusTree.h &#8211; BPlus tree for fast lookup, delete, and insert. DS_BytePool.h &#8211; Returns data blocks at certain size thresholds to reduce [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/309"}],"collection":[{"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=309"}],"version-history":[{"count":0,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/309\/revisions"}],"wp:attachment":[{"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rakkar.org\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}