Skip to content

Commit

Permalink
Add ExHashRing namespace all modules
Browse files Browse the repository at this point in the history
Both this package and `libring` export a `HashRing` module without
any top-level namespace. This diff adds a top-level namespace of
`ExHashRing` to avoid the conflict.

Fixes #3
  • Loading branch information
gmjosack committed Aug 15, 2018
1 parent 896543e commit a5cee4c
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/_build
/cover
/deps
/bench/snapshots
erl_crash.dump
*.ez
.DS_Store
.DS_Store
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ Add it to `mix.exs`.

```elixir
defp deps do
[{:ex_hash_ring, "~> 1.0"}]
[{:ex_hash_ring, "~> 3.0"}]
end
```

Create a new HashRing.

```elixir
alias ExHashRing.HashRing

ring = HashRing.new
{:ok, ring} = HashRing.add_node(ring, "a")
{:ok, ring} = HashRing.add_node(ring, "b")
Expand All @@ -37,7 +39,7 @@ Find the node for a key.
"b" = HashRing.find_node(ring, "key3")
```

Additionally, you can also use `HashRing.ETS`, which holds the ring in an ETS table for fast access, if you need
Additionally, you can also use `ExHashRing.HashRing.ETS`, which holds the ring in an ETS table for fast access, if you need
the ring across multiple processes.


Expand Down
2 changes: 1 addition & 1 deletion bench/ets_hash_ring_bench.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule ETSHashRingBench do
use Benchfella
alias HashRing.ETS, as: Ring
alias ExHashRing.HashRing.ETS, as: Ring


@nodes [
Expand Down
1 change: 1 addition & 0 deletions bench/hash_ring_bench.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule HashRingBench do
use Benchfella
alias ExHashRing.HashRing

@nodes [
"hash-ring-1-1",
Expand Down
4 changes: 2 additions & 2 deletions lib/ex_hash_ring.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ defmodule ExHashRing do
use Application

def start(_type, _args) do
HashRing.ETS.Config.start_link()
ExHashRing.HashRing.ETS.Config.start_link()
end
end
end
4 changes: 2 additions & 2 deletions lib/hash_ring.ex
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
defmodule HashRing do
defmodule ExHashRing.HashRing do
@compile :native

@type t :: __MODULE__

use Bitwise
alias HashRing.Utils
alias ExHashRing.HashRing.Utils

defstruct num_replicas: 0, nodes: [], items: {}

Expand Down
6 changes: 3 additions & 3 deletions lib/hash_ring/ets.ex
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
defmodule HashRing.ETS do
defmodule ExHashRing.HashRing.ETS do
@default_num_replicas 512
@default_ring_gen_gc_delay 10_000

@type t :: __MODULE__

use GenServer

alias HashRing.Utils
alias HashRing.ETS.Config
alias ExHashRing.HashRing.Utils
alias ExHashRing.HashRing.ETS.Config

defstruct default_num_replicas: @default_num_replicas,
nodes: [],
Expand Down
4 changes: 2 additions & 2 deletions lib/hash_ring/ets_config.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule HashRing.ETS.Config do
defmodule ExHashRing.HashRing.ETS.Config do
use GenServer

@type ring_gen :: integer
Expand Down Expand Up @@ -57,4 +57,4 @@ defmodule HashRing.ETS.Config do
end)
%{state | monitored_pids: monitored_pids}
end
end
end
4 changes: 2 additions & 2 deletions lib/utils.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule HashRing.Utils do
defmodule ExHashRing.HashRing.Utils do
@compile :native

@spec hash(atom | binary | integer) :: integer
Expand Down Expand Up @@ -27,4 +27,4 @@ defmodule HashRing.Utils do
end)
do_gen_items(nodes, items)
end
end
end
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
defmodule HashRing.Mixfile do
defmodule ExHashRing.HashRing.Mixfile do
use Mix.Project

def project do
[
app: :ex_hash_ring,
version: "2.0.0",
version: "3.0.0",
elixir: "~> 1.3",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
Expand Down
6 changes: 3 additions & 3 deletions test/ets_hash_ring_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule ETSHashRingTest do
use ExUnit.Case
alias HashRingTest.Support.Harness
alias HashRing.ETS, as: Ring
alias ExHashRing.HashRing.ETS, as: Ring

setup_all do
rings = for num_replicas <- Harness.replicas(), into: %{} do
Expand All @@ -28,7 +28,7 @@ end

defmodule ETSHashRingOperationsTest do
use ExUnit.Case
alias HashRing.ETS, as: Ring
alias ExHashRing.HashRing.ETS, as: Ring

@default_num_replicas 512
@nodes ["a", "b", "c"]
Expand Down Expand Up @@ -158,7 +158,7 @@ defmodule ETSHashRingOperationsTest do
assert Ring.find_nodes(HashRingEtsTest.DoesNotExist, 1, 2) == {:error, :no_ring}
end

test "HashRing.ETS.start_link/1" do
test "ExHashRing.HashRing.ETS.start_link/1" do
{:ok, _pid} = Ring.start_link(TestModule.Foo, nodes: @nodes)
assert Ring.find_node(TestModule.Foo, 1) == {:ok, "c"}
assert Process.whereis(TestModule.Foo) == nil
Expand Down
1 change: 1 addition & 0 deletions test/hash_ring_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule HashRingTest do
use ExUnit.Case
alias HashRingTest.Support.Harness
alias ExHashRing.HashRing

setup_all do
rings = for num_replicas <- Harness.replicas(), into: %{} do
Expand Down

0 comments on commit a5cee4c

Please sign in to comment.