Skip to content
Snippets Groups Projects
Commit d689ee06 authored by x18zhan2's avatar x18zhan2
Browse files

Implements: #44

parent 7be8edaa
No related branches found
No related tags found
No related merge requests found
Pipeline #1304 failed
......@@ -71,17 +71,20 @@ defmodule Index.Augmentation do
def issuersFrameVar(global_bindex, local_bindex) do
key = :ets.first(local_bindex)
[{key, head}] = :ets.lookup(local_bindex, key)
if head.number == 0 do
:ets.insert(local_bindex, {key, Map.merge(head, %{issuersFrameVar: 0})})
else
[[head_1_id]] = :dets.match(global_bindex, {:"$1", %{number: head.number - 1}})
[{_key_1, head_1}] = :dets.lookup(global_bindex, head_1_id)
variation = head_1.issuersFrameVar + 5 * (head.issuersCount - head_1.issuersCount)
case head_1.issuersFrameVar do
x when x > 0 -> variation - 1
x when x < 0 -> variation + 1
0 -> variation
end |> (&:ets.insert(local_bindex, {key, Map.merge(head, %{issuersFrameVar: &1})})).()
end
|> (&:ets.insert(local_bindex, {key, Map.merge(head, %{issuersFrameVar: &1})})).()
end
end
......@@ -118,6 +121,20 @@ defmodule Index.Augmentation do
end
end
def currency(global_bindex, local_bindex) do
key = :ets.first(local_bindex)
[{key, head}] = :ets.lookup(local_bindex, key)
if head.number > 0 do
[[currency]] =
:dets.match(global_bindex, {:_, %{number: head.number - 1, currency: :"$1"}})
:ets.insert(local_bindex, {key, Map.merge(head, %{currency: currency})})
else
:ets.insert(local_bindex, {key, Map.merge(head, %{currency: nil})})
end
end
def membersCount(local_iindex, global_bindex, local_bindex) do
key = :ets.first(local_bindex)
[{key, head}] = :ets.lookup(local_bindex, key)
......@@ -168,8 +185,10 @@ defmodule Index.Augmentation do
def toNewcomer(local_cindex, local_iindex, key) do
# Get the entry waiting to be verified
[{key, entry}] = :ets.lookup(local_cindex, key)
:ets.match(local_iindex, {:"$1", %{member: true, pub: entry.receiver}})
|>Enum.count()|>(fn x-> Map.merge(entry,%{toNewcomer: (x != 0) }) end).()
|> Enum.count()
|> (fn x -> Map.merge(entry, %{toNewcomer: x != 0}) end).()
|> (&:ets.insert(local_cindex, {key, &1})).()
end
end
......
defmodule Block.Augmentation.Currency do
use ExUnit.Case
doctest Index.Augmentation.BIndex
setup_all do
local_bindex = :ets.new(:local_bindex, [:set, :protected])
:ets.insert(local_bindex, {0, %{number: 0}})
:file.delete("test/global_bindex")
{:ok, global_bindex} = :dets.open_file(:"test/global_bindex", type: :set)
Index.Augmentation.BIndex.currency(global_bindex, local_bindex)
[{0, head}] = :ets.lookup(local_bindex, 0)
currency0 = head.currency
:ets.insert(local_bindex, {0, %{number: 1}})
:dets.insert(global_bindex, {0, %{number: 0, currency: "currencyTest"}})
Index.Augmentation.BIndex.currency(global_bindex, local_bindex)
[{0, head}] = :ets.lookup(local_bindex, 0)
currency1 = head.currency
:dets.close(global_bindex)
:file.delete("test/global_bindex")
{:ok, currency0: currency0, currency1: currency1}
end
test "check currency", state do
assert is_nil(state.currency0)
assert state.currency1 == "currencyTest"
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment