Format using mix format
and update some deps.
This commit is contained in:
parent
6f06407bf8
commit
95daf32624
7 changed files with 202 additions and 46 deletions
146
.credo.exs
Normal file
146
.credo.exs
Normal file
|
@ -0,0 +1,146 @@
|
|||
# This file contains the configuration for Credo and you are probably reading
|
||||
# this after creating it with `mix credo.gen.config`.
|
||||
#
|
||||
# If you find anything wrong or unclear in this file, please report an
|
||||
# issue on GitHub: https://github.com/rrrene/credo/issues
|
||||
#
|
||||
%{
|
||||
#
|
||||
# You can have as many configs as you like in the `configs:` field.
|
||||
configs: [
|
||||
%{
|
||||
#
|
||||
# Run any exec using `mix credo -C <name>`. If no exec name is given
|
||||
# "default" is used.
|
||||
#
|
||||
name: "default",
|
||||
#
|
||||
# These are the files included in the analysis:
|
||||
files: %{
|
||||
#
|
||||
# You can give explicit globs or simply directories.
|
||||
# In the latter case `**/*.{ex,exs}` will be used.
|
||||
#
|
||||
included: ["lib/", "src/", "web/", "apps/"],
|
||||
excluded: [~r"/_build/", ~r"/deps/"]
|
||||
},
|
||||
#
|
||||
# If you create your own checks, you must specify the source files for
|
||||
# them here, so they can be loaded by Credo before running the analysis.
|
||||
#
|
||||
requires: [],
|
||||
#
|
||||
# If you want to enforce a style guide and need a more traditional linting
|
||||
# experience, you can change `strict` to `true` below:
|
||||
#
|
||||
strict: false,
|
||||
#
|
||||
# If you want to use uncolored output by default, you can change `color`
|
||||
# to `false` below:
|
||||
#
|
||||
color: true,
|
||||
#
|
||||
# You can customize the parameters of any check by adding a second element
|
||||
# to the tuple.
|
||||
#
|
||||
# To disable a check put `false` as second element:
|
||||
#
|
||||
# {Credo.Check.Design.DuplicatedCode, false}
|
||||
#
|
||||
checks: [
|
||||
{Credo.Check.Consistency.ExceptionNames},
|
||||
{Credo.Check.Consistency.LineEndings},
|
||||
{Credo.Check.Consistency.ParameterPatternMatching},
|
||||
{Credo.Check.Consistency.SpaceAroundOperators},
|
||||
{Credo.Check.Consistency.SpaceInParentheses},
|
||||
{Credo.Check.Consistency.TabsOrSpaces},
|
||||
|
||||
# You can customize the priority of any check
|
||||
# Priority values are: `low, normal, high, higher`
|
||||
#
|
||||
{Credo.Check.Design.AliasUsage, priority: :low},
|
||||
|
||||
# For some checks, you can also set other parameters
|
||||
#
|
||||
# If you don't want the `setup` and `test` macro calls in ExUnit tests
|
||||
# or the `schema` macro in Ecto schemas to trigger DuplicatedCode, just
|
||||
# set the `excluded_macros` parameter to `[:schema, :setup, :test]`.
|
||||
#
|
||||
{Credo.Check.Design.DuplicatedCode, excluded_macros: []},
|
||||
|
||||
# You can also customize the exit_status of each check.
|
||||
# If you don't want TODO comments to cause `mix credo` to fail, just
|
||||
# set this value to 0 (zero).
|
||||
#
|
||||
{Credo.Check.Design.TagTODO, exit_status: 2},
|
||||
{Credo.Check.Design.TagFIXME},
|
||||
|
||||
{Credo.Check.Readability.FunctionNames},
|
||||
{Credo.Check.Readability.LargeNumbers},
|
||||
{Credo.Check.Readability.MaxLineLength, priority: :low, max_length: 120},
|
||||
{Credo.Check.Readability.ModuleAttributeNames},
|
||||
{Credo.Check.Readability.ModuleDoc},
|
||||
{Credo.Check.Readability.ModuleNames},
|
||||
{Credo.Check.Readability.ParenthesesOnZeroArityDefs},
|
||||
{Credo.Check.Readability.ParenthesesInCondition},
|
||||
{Credo.Check.Readability.PredicateFunctionNames},
|
||||
{Credo.Check.Readability.PreferImplicitTry},
|
||||
{Credo.Check.Readability.RedundantBlankLines},
|
||||
{Credo.Check.Readability.StringSigils},
|
||||
{Credo.Check.Readability.TrailingBlankLine},
|
||||
{Credo.Check.Readability.TrailingWhiteSpace},
|
||||
{Credo.Check.Readability.VariableNames},
|
||||
{Credo.Check.Readability.Semicolons},
|
||||
{Credo.Check.Readability.SpaceAfterCommas},
|
||||
|
||||
{Credo.Check.Refactor.DoubleBooleanNegation},
|
||||
{Credo.Check.Refactor.CondStatements},
|
||||
{Credo.Check.Refactor.CyclomaticComplexity},
|
||||
{Credo.Check.Refactor.FunctionArity},
|
||||
{Credo.Check.Refactor.LongQuoteBlocks},
|
||||
{Credo.Check.Refactor.MatchInCondition},
|
||||
{Credo.Check.Refactor.NegatedConditionsInUnless},
|
||||
{Credo.Check.Refactor.NegatedConditionsWithElse},
|
||||
{Credo.Check.Refactor.Nesting},
|
||||
{Credo.Check.Refactor.PipeChainStart},
|
||||
{Credo.Check.Refactor.UnlessWithElse},
|
||||
|
||||
{Credo.Check.Warning.BoolOperationOnSameValues},
|
||||
{Credo.Check.Warning.ExpensiveEmptyEnumCheck},
|
||||
{Credo.Check.Warning.IExPry},
|
||||
{Credo.Check.Warning.IoInspect},
|
||||
{Credo.Check.Warning.LazyLogging},
|
||||
{Credo.Check.Warning.OperationOnSameValues},
|
||||
{Credo.Check.Warning.OperationWithConstantResult},
|
||||
{Credo.Check.Warning.UnusedEnumOperation},
|
||||
{Credo.Check.Warning.UnusedFileOperation},
|
||||
{Credo.Check.Warning.UnusedKeywordOperation},
|
||||
{Credo.Check.Warning.UnusedListOperation},
|
||||
{Credo.Check.Warning.UnusedPathOperation},
|
||||
{Credo.Check.Warning.UnusedRegexOperation},
|
||||
{Credo.Check.Warning.UnusedStringOperation},
|
||||
{Credo.Check.Warning.UnusedTupleOperation},
|
||||
{Credo.Check.Warning.RaiseInsideRescue},
|
||||
|
||||
# Controversial and experimental checks (opt-in, just remove `, false`)
|
||||
#
|
||||
{Credo.Check.Refactor.ABCSize, false},
|
||||
{Credo.Check.Refactor.AppendSingleItem, false},
|
||||
{Credo.Check.Refactor.VariableRebinding, false},
|
||||
{Credo.Check.Warning.MapGetUnsafePass, false},
|
||||
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},
|
||||
|
||||
# Deprecated checks (these will be deleted after a grace period)
|
||||
#
|
||||
{Credo.Check.Readability.Specs, false},
|
||||
{Credo.Check.Warning.NameRedeclarationByAssignment, false},
|
||||
{Credo.Check.Warning.NameRedeclarationByCase, false},
|
||||
{Credo.Check.Warning.NameRedeclarationByDef, false},
|
||||
{Credo.Check.Warning.NameRedeclarationByFn, false},
|
||||
|
||||
# Custom checks can be created using `mix credo.gen.check`.
|
||||
#
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
23
lib/heap.ex
23
lib/heap.ex
|
@ -1,5 +1,6 @@
|
|||
defmodule Heap do
|
||||
defstruct data: nil, size: 0, comparator: nil
|
||||
|
||||
@moduledoc """
|
||||
A heap is a special tree data structure. Good for sorting and other magic.
|
||||
|
||||
|
@ -89,8 +90,9 @@ defmodule Heap do
|
|||
@spec new(:> | :<) :: t
|
||||
def new(:>), do: %Heap{comparator: :>}
|
||||
def new(:<), do: %Heap{comparator: :<}
|
||||
@spec new(((any, any) -> boolean)) :: t
|
||||
@spec new((any, any -> boolean)) :: t
|
||||
def new(fun) when is_function(fun, 2), do: %Heap{comparator: fun}
|
||||
|
||||
@doc """
|
||||
Test if `heap` is empty.
|
||||
|
||||
|
@ -129,9 +131,9 @@ defmodule Heap do
|
|||
"""
|
||||
@spec member?(t, any()) :: boolean()
|
||||
def member?(%Heap{} = heap, value) do
|
||||
root = Heap.root heap
|
||||
heap = Heap.pop heap
|
||||
has_member? heap, root, value
|
||||
root = Heap.root(heap)
|
||||
heap = Heap.pop(heap)
|
||||
has_member?(heap, root, value)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
@ -145,7 +147,8 @@ defmodule Heap do
|
|||
13
|
||||
"""
|
||||
@spec push(t, any()) :: t
|
||||
def push(%Heap{data: h, size: n, comparator: d}, value), do: %Heap{data: meld(h, {value, []}, d), size: n + 1, comparator: d}
|
||||
def push(%Heap{data: h, size: n, comparator: d}, value),
|
||||
do: %Heap{data: meld(h, {value, []}, d), size: n + 1, comparator: d}
|
||||
|
||||
@doc """
|
||||
Pop the root element off `heap` and discard it.
|
||||
|
@ -161,7 +164,9 @@ defmodule Heap do
|
|||
"""
|
||||
@spec pop(t) :: t
|
||||
def pop(%Heap{data: nil, size: 0} = _heap), do: nil
|
||||
def pop(%Heap{data: {_, q}, size: n, comparator: d} = _heap), do: %Heap{data: pair(q, d), size: n - 1, comparator: d}
|
||||
|
||||
def pop(%Heap{data: {_, q}, size: n, comparator: d} = _heap),
|
||||
do: %Heap{data: pair(q, d), size: n - 1, comparator: d}
|
||||
|
||||
@doc """
|
||||
Return the element at the root of `heap`.
|
||||
|
@ -240,6 +245,7 @@ defmodule Heap do
|
|||
|
||||
defp pair([], _), do: nil
|
||||
defp pair([q], _), do: q
|
||||
|
||||
defp pair([q0, q1 | q], d) do
|
||||
q2 = meld(q0, q1, d)
|
||||
meld(q2, pair(q, d), d)
|
||||
|
@ -247,8 +253,9 @@ defmodule Heap do
|
|||
|
||||
defp has_member?(_, previous, compare) when previous == compare, do: true
|
||||
defp has_member?(nil, _, _), do: false
|
||||
|
||||
defp has_member?(heap, _, compare) do
|
||||
{previous, heap} = Heap.split heap
|
||||
has_member? heap, previous, compare
|
||||
{previous, heap} = Heap.split(heap)
|
||||
has_member?(heap, previous, compare)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
defimpl Collectable, for: Heap do
|
||||
|
||||
@doc """
|
||||
Collect an enumerable into a heap.
|
||||
|
||||
|
@ -11,13 +10,13 @@ defimpl Collectable, for: Heap do
|
|||
...> |> Heap.root
|
||||
1
|
||||
"""
|
||||
@spec into(Heap.t) :: {list, function}
|
||||
@spec into(Heap.t()) :: {list, function}
|
||||
def into(heap) do
|
||||
{heap, fn
|
||||
(h, {:cont, v}) -> Heap.push(h, v)
|
||||
(h, :done) -> h
|
||||
(_, :halt) -> :ok
|
||||
{heap,
|
||||
fn
|
||||
h, {:cont, v} -> Heap.push(h, v)
|
||||
h, :done -> h
|
||||
_, :halt -> :ok
|
||||
end}
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
defimpl Enumerable, for: Heap do
|
||||
|
||||
@doc """
|
||||
Returns the number of elements in a heap.
|
||||
|
||||
|
@ -10,9 +9,9 @@ defimpl Enumerable, for: Heap do
|
|||
...> |> Enum.count()
|
||||
500
|
||||
"""
|
||||
@spec count(Heap.t) :: non_neg_integer
|
||||
@spec count(Heap.t()) :: non_neg_integer
|
||||
def count(heap) do
|
||||
{:ok, Heap.size heap}
|
||||
{:ok, Heap.size(heap)}
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
@ -30,7 +29,7 @@ defimpl Enumerable, for: Heap do
|
|||
...> |> Enum.member?(750)
|
||||
false
|
||||
"""
|
||||
@spec member?(Heap.t, term) :: boolean
|
||||
@spec member?(Heap.t(), term) :: boolean
|
||||
def member?(heap, value) do
|
||||
{:ok, Heap.member?(heap, value)}
|
||||
end
|
||||
|
@ -47,17 +46,18 @@ defimpl Enumerable, for: Heap do
|
|||
...> |> Enum.count()
|
||||
250
|
||||
"""
|
||||
@spec reduce(Heap.t, Enumerable.acc, Enumerable.reducer) :: Enumerable.result
|
||||
@spec reduce(Heap.t(), Enumerable.acc(), Enumerable.reducer()) :: Enumerable.result()
|
||||
def reduce(_, {:halt, acc}, _fun), do: {:halted, acc}
|
||||
def reduce(heap, {:suspend, acc}, fun), do: {:suspended, acc, &reduce(heap, &1, fun)}
|
||||
|
||||
def reduce(heap, {:cont, acc}, fun) do
|
||||
case Heap.root(heap) do
|
||||
nil ->
|
||||
{:done, acc}
|
||||
|
||||
root ->
|
||||
heap = Heap.pop(heap)
|
||||
reduce(heap, fun.(root, acc), fun)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ defimpl Inspect, for: Heap do
|
|||
...> |> inspect
|
||||
"#Heap<[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]>"
|
||||
"""
|
||||
@spec inspect(Heap.t, Inspect.Opts.t) :: Inspect.Algebra.t
|
||||
@spec inspect(Heap.t(), Inspect.Opts.t()) :: Inspect.Algebra.t()
|
||||
def inspect(heap, opts) do
|
||||
concat(["#Heap<", to_doc(Enum.to_list(heap), opts), ">"])
|
||||
end
|
||||
|
|
14
mix.exs
14
mix.exs
|
@ -2,14 +2,16 @@ defmodule Heap.Mixfile do
|
|||
use Mix.Project
|
||||
|
||||
def project do
|
||||
[app: :heap,
|
||||
[
|
||||
app: :heap,
|
||||
version: "2.0.0",
|
||||
description: description(),
|
||||
elixir: "~> 1.5",
|
||||
build_embedded: Mix.env == :prod,
|
||||
start_permanent: Mix.env == :prod,
|
||||
build_embedded: Mix.env() == :prod,
|
||||
start_permanent: Mix.env() == :prod,
|
||||
package: package(),
|
||||
deps: deps()]
|
||||
deps: deps()
|
||||
]
|
||||
end
|
||||
|
||||
# Configuration for the OTP application
|
||||
|
@ -25,8 +27,8 @@ defmodule Heap.Mixfile do
|
|||
|
||||
def package do
|
||||
[
|
||||
maintainers: [ "James Harton <james@automat.nz>" ],
|
||||
licenses: [ "MIT" ],
|
||||
maintainers: ["James Harton <james@automat.nz>"],
|
||||
licenses: ["MIT"],
|
||||
links: %{
|
||||
"GitHub" => "https://github.com/jamesotron/heap",
|
||||
"Docs" => "https://hexdocs.pm/heap"
|
||||
|
|
14
mix.lock
14
mix.lock
|
@ -1,8 +1,10 @@
|
|||
%{"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], []},
|
||||
"credo": {:hex, :credo, "0.8.6", "335f723772d35da499b5ebfdaf6b426bfb73590b6fcbc8908d476b75f8cbca3f", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, optional: false]}]},
|
||||
"earmark": {:hex, :earmark, "0.2.1", "ba6d26ceb16106d069b289df66751734802777a3cbb6787026dd800ffeb850f3", [:mix], []},
|
||||
%{
|
||||
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
|
||||
"credo": {:hex, :credo, "0.8.10", "261862bb7363247762e1063713bb85df2bbd84af8d8610d1272cd9c1943bba63", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [:mix], [], "hexpm"},
|
||||
"espec": {:hex, :espec, "0.8.28", "f002710673d215876c4ca6fc74cbf5e330954badea7389d2284d2050940f1779", [:mix], [{:meck, "~> 0.8.4", [hex: :meck, optional: false]}]},
|
||||
"ex_doc": {:hex, :ex_doc, "0.11.5", "0dc51cb84f8312162a2313d6c71573a9afa332333d8a332bb12540861b9834db", [:mix], [{:earmark, "~> 0.1.17 or ~> 0.2", [hex: :earmark, optional: true]}]},
|
||||
"inch_ex": {:hex, :inch_ex, "0.5.6", "418357418a553baa6d04eccd1b44171936817db61f4c0840112b420b8e378e67", [:mix], [{:poison, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :poison, optional: false]}]},
|
||||
"ex_doc": {:hex, :ex_doc, "0.18.2", "993e0a95e9fbb790ac54ea58e700b45b299bd48bc44b4ae0404f28161f37a83e", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"inch_ex": {:hex, :inch_ex, "0.5.6", "418357418a553baa6d04eccd1b44171936817db61f4c0840112b420b8e378e67", [:mix], [{:poison, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"meck": {:hex, :meck, "0.8.8", "eeb3efe811d4346e1a7f65b2738abc2ad73cbe1a2c91b5dd909bac2ea0414fa6", [:rebar3], []},
|
||||
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], []}}
|
||||
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue