Permalink
Browse files

fixed some docs and slightly changed the way gc provides advice

  • Loading branch information...
1 parent 2309c3c commit be0d2bdb3c9e29ce9ebfd73f3eaa1f7690e5951a @raganwald raganwald committed May 9, 2012
Showing with 24 additions and 32 deletions.
  1. +2 −5 docs/cafeaulife.html
  2. +10 −11 docs/gc.html
  3. +2 −5 lib/cafeaulife.coffee
  4. +10 −11 lib/gc.coffee
@@ -43,8 +43,7 @@
still incredible relative to brute force, which is a testimony of the importance of algorithms over implementations.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Cafe au Life is divided into modules:</p>
<ul>
-<li>The <a href="http:universe.html">Universe Module</a> introduces the <code>Cell</code> and <code>Square</code> classes that implement the <a href="https://en.wikipedia.org/wiki/Quadtree">Quadtree</a>, and it also
-provides a method for setting up the <a href="http://www.conwaylife.com/wiki/Cellular_automaton#Well-known_Life-like_cellular_automata">rules</a> of the Life universe.</li>
+<li>The <a href="http:universe.html">Universe Module</a> introduces the <code>Cell</code> and <code>Square</code> classes that implement the <a href="https://en.wikipedia.org/wiki/Quadtree">Quadtree</a>.</li>
<li>The <a href="http:future.html">Future Module</a> provides methods for computing the future of a square in the <a href="https://en.wikipedia.org/wiki/Quadtree">Quadtree</a>, making full use of recursion.</li>
<li>The <a href="http:canonicalization.html">Canonicalization Module</a> implements a very naive hash-table for canoncial representations of squares. HashLife uses extensive
<a href="https://en.wikipedia.org/wiki/Canonicalization">canonicalization</a> to optimize the storage of very large patterns with repetitive components. Without the cache, the
@@ -78,9 +77,7 @@
With the future module removed, it should still use a <a href="https://en.wikipedia.org/wiki/Quadtree">Quadtree</a>, but not cache results and notlook more than one generation into the future.
The <a href="https://en.wikipedia.org/wiki/Quadtree">Quadtree</a> is then simply a space-saving measure.</p>
-<p>TODO: Allow futures, but move <em>memoization</em> of futures into its own module.</p>
-
-<p>TODO: Support changing the rules during a run. The Canonicalization Module will ahve to regenerate the cache.</p>
+<p>TODO: Support changing the rules during a run. The Canonicalization Module will have to clear the cache.</p>
<p>TODO: Decouple canonicalization so that it can work with or without the Canonicalization Module. If the Canonicalization Module is removed, it should work VERY slowly.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <h2>Who</h2>
View
@@ -97,8 +97,7 @@
<span class="nv">removeRecursively: </span><span class="o">-&gt;</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <h3>Modifying <code>Square.RecursivelyComputable</code></h3>
<p>We take advantage of the way <code>Square.RecursivelyComputable</code> is factored to introduce reference
-counting and add methods to remove a recursively computable square from the cache.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">YouAreDaChef</span>
- <span class="p">.</span><span class="nx">tag</span><span class="p">(</span><span class="s1">&#39;gc&#39;</span><span class="p">)</span>
+counting and add methods to remove a recursively computable square from the cache.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">YouAreDaChef</span><span class="p">(</span><span class="s1">&#39;gc&#39;</span><span class="p">)</span>
<span class="p">.</span><span class="nx">clazz</span><span class="p">(</span><span class="nx">Square</span><span class="p">)</span>
<span class="p">.</span><span class="nx">def</span>
<span class="nv">has_references: </span><span class="o">-&gt;</span>
@@ -133,15 +132,15 @@
<span class="nx">_</span><span class="p">.</span><span class="nx">each</span> <span class="nx">@children</span><span class="p">(),</span> <span class="nf">(v) -&gt;</span>
<span class="nx">v</span><span class="p">.</span><span class="nx">decrementReference</span><span class="p">()</span>
<span class="nx">v</span><span class="p">.</span><span class="nx">removeRecursively</span><span class="p">()</span>
- <span class="p">.</span><span class="nx">before</span>
- <span class="nv">set_memo: </span><span class="nf">(index) -&gt;</span>
- <span class="k">if</span> <span class="p">(</span><span class="nv">existing = </span><span class="nx">@get_memo</span><span class="p">(</span><span class="nx">index</span><span class="p">))</span>
- <span class="nx">existing</span><span class="p">.</span><span class="nx">decrementReference</span><span class="p">()</span>
- <span class="p">.</span><span class="nx">after</span>
- <span class="nv">initialize : </span><span class="o">-&gt;</span>
- <span class="vi">@references = </span><span class="mi">0</span>
- <span class="nv">set_memo: </span><span class="nf">(index, square) -&gt;</span>
- <span class="nx">square</span><span class="p">.</span><span class="nx">incrementReference</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <h3>Naïve Garbage Collection</h3>
+ <span class="p">.</span><span class="nx">method</span><span class="p">(</span><span class="s1">&#39;initialize&#39;</span><span class="p">)</span>
+ <span class="p">.</span><span class="nx">after</span> <span class="o">-&gt;</span>
+ <span class="vi">@references = </span><span class="mi">0</span>
+ <span class="p">.</span><span class="nx">method</span><span class="p">(</span><span class="s1">&#39;set_memo&#39;</span><span class="p">)</span>
+ <span class="p">.</span><span class="nx">before</span> <span class="nf">(index) -&gt;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nv">existing = </span><span class="nx">@get_memo</span><span class="p">(</span><span class="nx">index</span><span class="p">))</span>
+ <span class="nx">existing</span><span class="p">.</span><span class="nx">decrementReference</span><span class="p">()</span>
+ <span class="p">.</span><span class="nx">after</span> <span class="nf">(index, square) -&gt;</span>
+ <span class="nx">square</span><span class="p">.</span><span class="nx">incrementReference</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <h3>Naïve Garbage Collection</h3>
<p>Our GC is pretty bone-headed, it uses brute force to get a list of
removeable squares, then marches through them from highest to lowest
@@ -57,8 +57,7 @@
# Cafe au Life is divided into modules:
#
-# * The [Universe Module][universe] introduces the `Cell` and `Square` classes that implement the [Quadtree](https://en.wikipedia.org/wiki/Quadtree), and it also
-# provides a method for setting up the [rules][ll] of the Life universe.
+# * The [Universe Module][universe] introduces the `Cell` and `Square` classes that implement the [Quadtree](https://en.wikipedia.org/wiki/Quadtree).
# * The [Future Module][future] provides methods for computing the future of a square in the [Quadtree](https://en.wikipedia.org/wiki/Quadtree), making full use of recursion.
# * The [Canonicalization Module][canonicalization] implements a very naive hash-table for canoncial representations of squares. HashLife uses extensive
# [canonicalization][canonical] to optimize the storage of very large patterns with repetitive components. Without the cache, the
@@ -120,9 +119,7 @@ _.defaults exports, universe
# With the future module removed, it should still use a [Quadtree](https://en.wikipedia.org/wiki/Quadtree), but not cache results and notlook more than one generation into the future.
# The [Quadtree](https://en.wikipedia.org/wiki/Quadtree) is then simply a space-saving measure.
#
-# TODO: Allow futures, but move *memoization* of futures into its own module.
-#
-# TODO: Support changing the rules during a run. The Canonicalization Module will ahve to regenerate the cache.
+# TODO: Support changing the rules during a run. The Canonicalization Module will have to clear the cache.
#
# TODO: Decouple canonicalization so that it can work with or without the Canonicalization Module. If the Canonicalization Module is removed, it should work VERY slowly.
View
@@ -114,8 +114,7 @@ exports.mixInto = ({Square, Cell}) ->
#
# We take advantage of the way `Square.RecursivelyComputable` is factored to introduce reference
# counting and add methods to remove a recursively computable square from the cache.
- YouAreDaChef
- .tag('gc')
+ YouAreDaChef('gc')
.clazz(Square)
.def
has_references: ->
@@ -150,15 +149,15 @@ exports.mixInto = ({Square, Cell}) ->
_.each @children(), (v) ->
v.decrementReference()
v.removeRecursively()
- .before
- set_memo: (index) ->
- if (existing = @get_memo(index))
- existing.decrementReference()
- .after
- initialize : ->
- @references = 0
- set_memo: (index, square) ->
- square.incrementReference()
+ .method('initialize')
+ .after ->
+ @references = 0
+ .method('set_memo')
+ .before (index) ->
+ if (existing = @get_memo(index))
+ existing.decrementReference()
+ .after (index, square) ->
+ square.incrementReference()
# ### Naïve Garbage Collection

0 comments on commit be0d2bd

Please sign in to comment.