<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">Data structures – Haskell – Aelve Guide</title><id>https://guide.aelve.com/haskell/feed/category/fum5aqch</id><updated>2019-05-07T08:32:56Z</updated><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/feed/category/fum5aqch"/><entry><id>ecmbedsw</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">treap</title><updated>2019-05-07T08:32:56Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;a href=&#34;https://github.com/chshersh/treap&#34; class=&#34;item-name&#34;&gt;treap&lt;/a&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/treap&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;p&gt;The &lt;code&gt;treap&lt;/code&gt; package implements a tree-like data structure called &lt;em&gt;implicit treap&lt;/em&gt;. This
data structure implements interface similar to random-access arrays, but with
fast (logarithmic time complexity)
&lt;code&gt;insert&lt;/code&gt;/&lt;code&gt;delete&lt;/code&gt;/&lt;code&gt;split&lt;/code&gt;/&lt;code&gt;merge&lt;/code&gt;/&lt;code&gt;take&lt;/code&gt;/&lt;code&gt;drop&lt;/code&gt;/&lt;code&gt;rotate&lt;/code&gt; operations. In addition,
&lt;em&gt;treap&lt;/em&gt; allows you to specify and measure values of any monoids on a segment,
like a sum of elements or minimal element on some contiguous part of the array.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;When to use?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Use this package when you want the following operations to be fast:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Access elements by index.&lt;/li&gt;
&lt;li&gt;Insert elements by index.&lt;/li&gt;
&lt;li&gt;Delete elements by index.&lt;/li&gt;
&lt;li&gt;Calculate monoidal operation (like sum, product, min, etc.) of all elements
between two indices.&lt;/li&gt;
&lt;li&gt;Call slicing operations like &lt;code&gt;take&lt;/code&gt; or &lt;code&gt;drop&lt;/code&gt; or &lt;code&gt;split&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/data-structures-fum5aqch#item-ecmbedsw"/></entry><entry><id>lzi24lq7</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">slist</title><updated>2019-05-07T08:28:10Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;a href=&#34;https://github.com/vrom911/slist&#34; class=&#34;item-name&#34;&gt;slist&lt;/a&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/slist&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;p&gt;This package introduces sized list data type — Slist. The data type has the following shape:&lt;/p&gt;
&lt;div class=&#34;sourceCode&#34;&gt;&lt;pre class=&#34;sourceCode&#34;&gt;&lt;code class=&#34;sourceCode&#34;&gt;&lt;span class=&#34;kw&#34;&gt;data&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;Slist&lt;/span&gt; a &lt;span class=&#34;fu&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;Slist&lt;/span&gt;
    {&lt;span class=&#34;ot&#34;&gt; sList ::&lt;/span&gt; [a]
    ,&lt;span class=&#34;ot&#34;&gt; sSize ::&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;Size&lt;/span&gt;
    }&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As you can see along with the familiar list, it contains Size field that represents the size of the structure. Slists can be finite or infinite, and this is expressed with Size.&lt;/p&gt;
&lt;div class=&#34;sourceCode&#34;&gt;&lt;pre class=&#34;sourceCode&#34;&gt;&lt;code class=&#34;sourceCode&#34;&gt;&lt;span class=&#34;kw&#34;&gt;data&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;Size&lt;/span&gt;
    &lt;span class=&#34;fu&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;Size&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;Int&lt;/span&gt;
    &lt;span class=&#34;fu&#34;&gt;|&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;Infinity&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This representation of the list gives some additional advantages. Getting the length of the list is the &amp;quot;free&amp;quot; operation (runs in O(1)). This property helps to improve the performance for a bunch of functions like take, drop, at, etc. But also it doesn&#39;t actually add any overhead on the existing functions.&lt;/p&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/data-structures-fum5aqch#item-lzi24lq7"/></entry><entry><id>zeitsm5j</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">algebraic-graphs</title><updated>2018-10-14T17:27:18Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;algebraic-graphs&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/algebraic-graphs&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;p&gt;&lt;a href=&#34;https://github.com/snowleopard/alga&#34;&gt;Alga&lt;/a&gt; (this package) is a library for algebraic construction and manipulation of graphs in Haskell. See the &lt;a href=&#34;https://github.com/snowleopard/alga/blob/master/README.md&#34;&gt;README&lt;/a&gt; for more information.&lt;/p&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/data-structures-fum5aqch#item-zeitsm5j"/></entry><entry><id>ahtidepm</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">dlist</title><updated>2017-09-28T17:30:13Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;dlist&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/dlist&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;p&gt;A list-like type supporting O(1) append, useful for efficient logging and pretty printing.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Using DList as the state type when printing a tree with the Writer monad &lt;a href=&#34;https://hackage.haskell.org/package/dlist-0.8.0.3/docs/Data-DList.html&#34;&gt;from dlist docs&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;sourceCode&#34;&gt;&lt;pre class=&#34;sourceCode&#34;&gt;&lt;code class=&#34;sourceCode&#34;&gt;&lt;span class=&#34;kw&#34;&gt;import &lt;/span&gt;&lt;span class=&#34;dt&#34;&gt;Control.Monad.Writer&lt;/span&gt;
&lt;span class=&#34;kw&#34;&gt;import &lt;/span&gt;&lt;span class=&#34;dt&#34;&gt;Data.DList&lt;/span&gt;

&lt;span class=&#34;kw&#34;&gt;data&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;Tree&lt;/span&gt; a &lt;span class=&#34;fu&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;Leaf&lt;/span&gt; a &lt;span class=&#34;fu&#34;&gt;|&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;Branch&lt;/span&gt; (&lt;span class=&#34;dt&#34;&gt;Tree&lt;/span&gt; a) (&lt;span class=&#34;dt&#34;&gt;Tree&lt;/span&gt; a)

&lt;span class=&#34;ot&#34;&gt;flatten_writer ::&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;Tree&lt;/span&gt; x &lt;span class=&#34;ot&#34;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&#34;dt&#34;&gt;DList&lt;/span&gt; x
flatten_writer &lt;span class=&#34;fu&#34;&gt;=&lt;/span&gt; snd &lt;span class=&#34;fu&#34;&gt;.&lt;/span&gt; runWriter &lt;span class=&#34;fu&#34;&gt;.&lt;/span&gt; flatten
    &lt;span class=&#34;kw&#34;&gt;where&lt;/span&gt;
      flatten (&lt;span class=&#34;dt&#34;&gt;Leaf&lt;/span&gt; x)     &lt;span class=&#34;fu&#34;&gt;=&lt;/span&gt; tell (singleton x)
      flatten (&lt;span class=&#34;dt&#34;&gt;Branch&lt;/span&gt; x y) &lt;span class=&#34;fu&#34;&gt;=&lt;/span&gt; flatten x &lt;span class=&#34;fu&#34;&gt;&amp;gt;&amp;gt;&lt;/span&gt; flatten y&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/data-structures-fum5aqch#item-ahtidepm"/></entry><entry><id>w6xvu3mz</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">fgl</title><updated>2017-09-28T17:30:09Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;fgl&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/fgl&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;p&gt;An inductive representation of manipulating graph data structures.&lt;/p&gt;
&lt;p&gt;TODO: better description.&lt;/p&gt;
&lt;h2&gt;Notes&lt;/h2&gt;&lt;h1&gt;&lt;span id=&#34;item-notes-w6xvu3mz-links&#34;&gt;&lt;/span&gt;Links&lt;/h1&gt;&lt;p&gt;Links to tutorials, blog posts, etc.&lt;/p&gt;
&lt;h1&gt;&lt;span id=&#34;item-notes-w6xvu3mz-imports&#34;&gt;&lt;/span&gt;Imports&lt;/h1&gt;&lt;p&gt;Most commonly used imports from the library&lt;/p&gt;
&lt;h1&gt;&lt;span id=&#34;item-notes-w6xvu3mz-usage&#34;&gt;&lt;/span&gt;Usage&lt;/h1&gt;&lt;p&gt;Some examples&lt;/p&gt;
&lt;h1&gt;&lt;span id=&#34;item-notes-w6xvu3mz-gotchas&#34;&gt;&lt;/span&gt;Gotchas&lt;/h1&gt;&lt;p&gt;Common mistakes and non-obvious things&lt;/p&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/data-structures-fum5aqch#item-w6xvu3mz"/></entry><entry><id>z6v01opk</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">bytestring-trie</title><updated>2017-09-28T17:30:06Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;bytestring-trie&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/bytestring-trie&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;p&gt;An efficient finite map from (byte)strings to values.&lt;/p&gt;
&lt;p&gt;If all you need to do is associate strings to values you should use either &lt;code&gt;Map&lt;/code&gt; from &lt;a href=&#34;https://hackage.haskell.org/package/containers&#34;&gt;containers&lt;/a&gt; or &lt;code&gt;HashMap&lt;/code&gt; from &lt;a href=&#34;https://hackage.haskell.org/package/unordered-containers&#34;&gt;unordered-containers&lt;/a&gt;. You should only use this if you need the extra capabilities that a trie can provide (structure sharing for highly redundant keys, submap of all keys with a given prefix, extracting minimum and maximum keys, etc).&lt;/p&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/data-structures-fum5aqch#item-z6v01opk"/></entry><entry><id>fxxab7bd</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">HList</title><updated>2017-09-28T17:29:59Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;HList&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/HList&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;p&gt;Creation and manipulation of heterogenous lists (HLists) whose length and element types are known at compile-time.&lt;/p&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/data-structures-fum5aqch#item-fxxab7bd"/></entry><entry><id>yaffr9ei</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">unordered-containers</title><updated>2017-09-27T20:11:48Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;unordered-containers&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/unordered-containers&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;p&gt;Efficient hashing-based container types including &lt;code&gt;HashSet&lt;/code&gt; and &lt;code&gt;HashMap&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Strict or Lazy hashmap?&lt;/em&gt; If:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;you will eventually need all the values stored, or&lt;/li&gt;
&lt;li&gt;the stored values don&#39;t represent large virtual data structures to be lazily computed&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;then you should use the &lt;code&gt;Data.HashMap.Strict&lt;/code&gt;.&lt;/p&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/data-structures-fum5aqch#item-yaffr9ei"/></entry><entry><id>ngc92ehv</id><title xmlns:ns="http://www.w3.org/2005/Atom" ns:type="text">containers</title><updated>2017-09-27T20:11:43Z</updated><content xmlns:ns="http://www.w3.org/2005/Atom" ns:type="html">&lt;h1&gt;  &lt;span class=&#34;item-name&#34;&gt;containers&lt;/span&gt;

  
  (&lt;a href=&#34;https://hackage.haskell.org/package/containers&#34;&gt;Hackage&lt;/a&gt;)
&lt;/h1&gt;&lt;p&gt;Efficient general-purpose implementations of various immutable ordered container types. This package includes: &lt;code&gt;Map&lt;/code&gt;s, &lt;code&gt;Set&lt;/code&gt;s, &lt;code&gt;Tree&lt;/code&gt;s, &lt;code&gt;Graph&lt;/code&gt;s, and &lt;code&gt;Seq&lt;/code&gt;s.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Strict or Lazy map?&lt;/em&gt; If:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;you will eventually need all the values stored, or&lt;/li&gt;
&lt;li&gt;the stored values don&#39;t represent large virtual data structures to be lazily computed&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;then you should use the strict version of each of the container type (&lt;code&gt;Data.IntMap.Strict&lt;/code&gt;, &lt;code&gt;Data.Map.Strict&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Tutorial: &lt;a href=&#34;https://haskell-containers.readthedocs.io&#34;&gt;https://haskell-containers.readthedocs.io&lt;/a&gt;.&lt;/p&gt;
</content><link xmlns:ns="http://www.w3.org/2005/Atom" ns:href="https://guide.aelve.com/haskell/data-structures-fum5aqch#item-ngc92ehv"/></entry></feed>