<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -20,30 +20,51 @@
 %% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 %% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 %% OTHER DEALINGS IN THE SOFTWARE.
-
+%% 
+%% Change Log
+%%  * 2008-10-15 ngerakines, v0.2
+%%    - Added edoc friendly documentation.
+%%    - Added a patch submitted by Sergei Matusevich.
+%%    - Misc module organization and layout changes.
+%% 
+%% @author Nick Gerakines &lt;nick@gerakines.net&gt; [http://blog.socklabs.com/]
+%% @copyright 2008 Nick Gerakines
+%% @doc A module that provides basic geohash encoding and decoding.
 -module(geohash).
--compile(export_all).
+
+-export([encode/2, encode/3, decode/1]).
 
 -author(&quot;Nick Gerakines &lt;nick@gerakines.net&gt;&quot;).
--version(&quot;0.1&quot;).
+-version(&quot;0.2&quot;).
 
--include_lib(&quot;eunit/include/eunit.hrl&quot;).
+-ifdef(TEST).
 
-%% -
-%% Unit tests
+-include_lib(&quot;eunit/include/eunit.hrl&quot;).
 
 geohash_test_() -&gt;
     Tests = [
         {42.6, -5.6, &quot;ezs42&quot;}, {-20, 50, &quot;mh7w&quot;}, {10.1, 57.2, &quot;t3b9m&quot;},
         {49.26, -123.26, &quot;c2b25p&quot;}, {0.005, -179.567, &quot;80021bgm&quot;},
         {-30.55555, 0.2, &quot;k484ht99h2&quot;}, {5.00001, -140.6, &quot;8buh2w4pnt&quot;}],
-    [?_assert(geohash:encode(A, B) == C) || {A, B, C} &lt;- Tests],
-    % [?_assert(geohash:decode(C) == [A, B]) || {A, B, C} &lt;- Tests],
-    ok.
+    [?_assert(encode(A, B) == C) || {A, B, C} &lt;- Tests].
+
+-endif.
+
+%% @doc Create a hash for a given latitude and longitude.
+encode(Lat, Lon) when is_number(Lat), is_number(Lon) -&gt;
+    Pres = precision(Lat, Lon),
+    encode(Lat, Lon, Pres).
 
-%% -
-%% Base32 encoding
+%% @doc Create a hash for a given latitude and longitude with a specific precision.
+encode(Lat, Lon, Pres) when is_number(Lat), is_number(Lon), is_number(Pres) -&gt;
+    encode_major(Pres, {Lat, Lon}, {{90, -90}, {180, -180}}, 1, []).
 
+%% @doc Decode a geohash into a latitude and longitude.
+decode(Hash) when is_list(Hash) -&gt;
+    Set = decode_interval(Hash),
+    [mid(X, Set) || X &lt;- [0, 1]].
+
+%% @private
 base_32() -&gt; [
     {0, $0}, {1, $1}, {2, $2}, {3, $3}, {4, $4}, {5, $5}, {6, $6}, {7, $7},
     {8, $8}, {9, $9}, {10, $b}, {11, $c}, {12, $d}, {13, $e}, {14, $f},
@@ -52,86 +73,82 @@ base_32() -&gt; [
     {29, $x}, {30, $y}, {31, $z}
 ].
 
-encode_base32(X) -&gt; {value, {_, Y}} = lists:keysearch(X, 1, base_32()), Y.
-
-decode_base32(X) -&gt; {value, {Y, _}} = lists:keysearch(X, 2, base_32()), Y.
-
-%% -
-%% encode functionality
+%% @private
+encode_base32(X) when is_integer(X), X &gt; -1, X &lt; 32 -&gt;
+    {value, {_, Y}} = lists:keysearch(X, 1, base_32()),
+    Y.
 
-encode(Lat, Lon) -&gt;
-    Pres = geohash:precision(Lat, Lon),
-    geohash:encode(Lat, Lon, Pres).
-
-encode(Lat, Lon, Pres) -&gt;
-    geohash:encode_major(Pres, {Lat, Lon}, {{90, -90}, {180, -180}}, 1, []).
+%% @private
+decode_base32(X) when is_integer(X) -&gt;
+    {value, {Y, _}} = lists:keysearch(X, 2, base_32()),
+    Y.
 
+%% @private
 encode_major(0, {_Lat, _Lon}, _Set, _Flip, Acc) -&gt; lists:reverse(Acc);
 encode_major(X, {Lat, Lon}, Set, Flip, Acc) -&gt;
-    {Code, NewSet, NewFlip} = geohash:encode_minor(0, {Lat, Lon}, Set, 0, Flip),
+    {Code, NewSet, NewFlip} = encode_minor(0, {Lat, Lon}, Set, 0, Flip),
     encode_major(X - 1, {Lat, Lon}, NewSet, NewFlip, [Code | Acc]).
 
+%% @private
 encode_minor(5, _, Set, Bits, Flip) -&gt; {encode_base32(Bits), Set, Flip};
 encode_minor(X, {Lat, Lon}, Set, Bits, Flip) -&gt;
-    Mid = geohash:mid(Flip, Set),
-    Bit = case geohash:latlon(Flip, {Lat, Lon}) &gt;= Mid of true -&gt; 1; _ -&gt; 0 end,
+    Mid = mid(Flip, Set),
+    Bit = case latlon(Flip, {Lat, Lon}) &gt;= Mid of true -&gt; 1; _ -&gt; 0 end,
     NewBits = (Bits bsl 1) bor Bit,
-    NewSet = geohash:shiftset(Set, Flip, Bit, Mid),
-    encode_minor(X + 1, {Lat, Lon}, NewSet, NewBits, geohash:flip(Flip)).
-
-%% -
-%% decode functionality
-
-%% [ X / 10000000 || X&lt;-geohash:decode(&quot;ezs42&quot;)]
-%% [ X / 10000000 || X&lt;-geohash:decode(&quot;8buh2w4pnt&quot;)]
-decode(Hash) -&gt;
-    Set = decode_interval(Hash),
-    [mid(X, Set) || X &lt;- [0, 1]].
+    NewSet = shiftset(Set, Flip, Bit, Mid),
+    encode_minor(X + 1, {Lat, Lon}, NewSet, NewBits, flip(Flip)).
 
+%% @private
 decode_interval(Hash) -&gt;
     M = 1,
     decode_major(Hash, 1, {{90 * M, -90 * M}, {180 * M, -180 * M}}).
 
+%% @private
 decode_major([], _Flip, Set) -&gt; Set;
 decode_major([Char | Chars], Flip, Set) -&gt;
     Bits = decode_base32(Char),
-    {NewSet, NewFlip} = geohash:decode_minor(0, Set, Bits, Flip),
+    {NewSet, NewFlip} = decode_minor(0, Set, Bits, Flip),
     decode_major(Chars, NewFlip, NewSet).
 
+%% @private
 decode_minor(5, Set, _Bits, Flip) -&gt; {Set, Flip};
 decode_minor(X, Set, Bits, Flip) -&gt;
-    Mid = geohash:mid(Flip, Set),
+    Mid = mid(Flip, Set),
     BitPos = (Bits band 16 ) bsr 4,
-    NewSet = geohash:shiftset(Set, Flip, BitPos, Mid),
-    decode_minor(X + 1, NewSet, Bits bsl 1, geohash:flip(Flip)).
-
-%% -
-%% private methods
+    NewSet = shiftset(Set, Flip, BitPos, Mid),
+    decode_minor(X + 1, NewSet, Bits bsl 1, flip(Flip)).
 
+%% @private
 flip(0) -&gt; 1;
 flip(_) -&gt; 0.
 
+%% @private
 shiftset({{A, B}, {_, D}}, 1, BitPos, New) when BitPos == 0 -&gt; {{A, B}, {New, D}};
 shiftset({{A, B}, {C, _}}, 1, 1, New) -&gt; {{A, B}, {C, New}};
 shiftset({{_, B}, {C, D}}, 0, BitPos, New) when BitPos == 0 -&gt; {{New, B}, {C, D}};
 shiftset({{A, _}, {C, D}}, 0, 1, New) -&gt; {{A, New}, {C, D}}.
 
+%% @private
 latlon(0, {X, _}) -&gt; X;
 latlon(1, {_, X}) -&gt; X.
 
+%% @private
 mid(0, {{A, B}, _}) -&gt; (A + B) / 2;
 mid(1, {_, {A, B}}) -&gt; (A + B) / 2.
 
+%% @private
 d2b(X) -&gt; round((X * 3.32192809488736)).
 
+%% @private
 bit_for_number(N) when is_float(N) -&gt;
     [RawChars] = io_lib:fwrite(&quot;~f&quot;, [N]),
     [_ | [FChars]] = string:tokens(string:strip(RawChars, right, $0), &quot;.&quot;),
-    geohash:d2b(length(FChars));
+    d2b(length(FChars));
 bit_for_number(_) -&gt; 0.
 
+%% @private
 precision(Lat, Lon) -&gt;
-    Lab = geohash:bit_for_number(Lat) + 8,
-    Lob = geohash:bit_for_number(Lon) + 9,
+    Lab = bit_for_number(Lat) + 8,
+    Lob = bit_for_number(Lon) + 9,
     Lux = case Lab &gt; Lob of true -&gt; Lab; _ -&gt; Lob end,
     round(Lux / 2.5).</diff>
      <filename>geohash.erl</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>0a7acb68978235a15f704fd8dbec730ddac0e9bf</id>
    </parent>
  </parents>
  <author>
    <name>Nick Gerakines</name>
    <email>nick@gerakines.net</email>
  </author>
  <url>http://github.com/ngerakines/erlang_geohash/commit/bb035e03d6120660ccf17b41f3cd7e4fe53a3c35</url>
  <id>bb035e03d6120660ccf17b41f3cd7e4fe53a3c35</id>
  <committed-date>2008-10-15T16:55:25-07:00</committed-date>
  <authored-date>2008-10-15T16:55:25-07:00</authored-date>
  <message>Bumping to 0.2. Added patch by Sergei Matusevich for cleaner base32 encoding and decoding.</message>
  <tree>1d99202fd093b5589213d818902191a250a23455</tree>
  <committer>
    <name>Nick Gerakines</name>
    <email>nick@gerakines.net</email>
  </committer>
</commit>
