-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HN-237 basic new structure and insertion at root
- Loading branch information
0 parents
commit 6e529b2
Showing
8 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Used by "mix format" | ||
[ | ||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# The directory Mix will write compiled artifacts to. | ||
/_build/ | ||
|
||
# If you run "mix test --cover", coverage assets end up here. | ||
/cover/ | ||
|
||
# The directory Mix downloads your dependencies sources to. | ||
/deps/ | ||
|
||
# Where third-party dependencies like ExDoc output generated docs. | ||
/doc/ | ||
|
||
# Ignore .fetch files in case you like to edit your project deps locally. | ||
/.fetch | ||
|
||
# If the VM crashes, it generates a dump, let's ignore it too. | ||
erl_crash.dump | ||
|
||
# Also ignore archive artifacts (built via "mix archive.build"). | ||
*.ez | ||
|
||
# Ignore package tarball (built via "mix hex.build"). | ||
elixir_rtree-*.tar | ||
|
||
# Ignore IntelliJ | ||
/.idea/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# ElixirRtree | ||
|
||
**TODO: Add description** | ||
|
||
## Installation | ||
|
||
If [available in Hex](https://hex.pm/docs/publish), the package can be installed | ||
by adding `elixir_rtree` to your list of dependencies in `mix.exs`: | ||
|
||
```elixir | ||
def deps do | ||
[ | ||
{:elixir_rtree, "~> 0.1.0"} | ||
] | ||
end | ||
``` | ||
|
||
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) | ||
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can | ||
be found at [https://hexdocs.pm/elixir_rtree](https://hexdocs.pm/elixir_rtree). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="ELIXIR_MODULE" version="4"> | ||
<component name="NewModuleRootManager"> | ||
<output url="file://$MODULE_DIR$/_build/dev/lib/elixir_rtree/ebin" /> | ||
<output-test url="file://$MODULE_DIR$/_build/test/lib/elixir_rtree/ebin" /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" /> | ||
<excludeFolder url="file://$MODULE_DIR$/assets/node_modules/phoenix" /> | ||
<excludeFolder url="file://$MODULE_DIR$/assets/node_modules/phoenix_html" /> | ||
<excludeFolder url="file://$MODULE_DIR$/cover" /> | ||
<excludeFolder url="file://$MODULE_DIR$/deps" /> | ||
<excludeFolder url="file://$MODULE_DIR$/doc" /> | ||
<excludeFolder url="file://$MODULE_DIR$/logs" /> | ||
</content> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
defmodule ElixirRtree do | ||
|
||
|
||
def new(width \\ 6)do | ||
w = [{:min_width,:math.floor(width) / 2.0},{:max_width,width}] | ||
ets = :ets.new(:rtree,[:set]) | ||
|
||
tree = %{ | ||
:metadata => %{params: w, ets_table: ets}, | ||
'root' => [] | ||
} | ||
|
||
:ets.insert(ets,{:metadata,Map.get(tree,:metadata)}) | ||
:ets.insert(ets,{'root', | ||
{Map.get(tree,'root'),[{:x,{0,0}},{:y,{0,0}}]} | ||
}) | ||
tree | ||
end | ||
|
||
def insert(tree,{box,id} = leaf)do | ||
meta = tree[:metadata] | ||
params = meta[:params] | ||
|
||
recursive_insertion(%{ | ||
tree: tree, | ||
max_width: params[:max_width], | ||
min_width: params[:min_width], | ||
ets: meta[:ets_table] | ||
},'root',id) | ||
|
||
end | ||
|
||
def recursive_insertion(rbundle,key,leaf)do | ||
|
||
childs = rbundle.tree |> Map.get(key) | ||
available_space = rbundle.max_width - length(childs) | ||
tree_update = case available_space do | ||
x when x > 0 -> rbundle.tree |> Map.update!(key,fn ch -> [leaf.id] ++ ch end) | ||
_ -> IO.puts "Merge" | ||
end | ||
|
||
tree_update | ||
end | ||
|
||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
defmodule ElixirRtree.MixProject do | ||
use Mix.Project | ||
|
||
def project do | ||
[ | ||
app: :elixir_rtree, | ||
version: "0.1.0", | ||
elixir: "~> 1.9", | ||
start_permanent: Mix.env() == :prod, | ||
deps: deps() | ||
] | ||
end | ||
|
||
# Run "mix help compile.app" to learn about applications. | ||
def application do | ||
[ | ||
extra_applications: [:logger] | ||
] | ||
end | ||
|
||
# Run "mix help deps" to learn about dependencies. | ||
defp deps do | ||
[ | ||
# {:dep_from_hexpm, "~> 0.3.0"}, | ||
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} | ||
] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
defmodule ElixirRtreeTest do | ||
use ExUnit.Case | ||
doctest ElixirRtree | ||
|
||
test "greets the world" do | ||
assert ElixirRtree.hello() == :world | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ExUnit.start() |