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

implements:#73

parent d689ee06
Branches
No related tags found
No related merge requests found
Pipeline #1320 failed
......@@ -122,8 +122,7 @@ defmodule Index.Augmentation do
end
def currency(global_bindex, local_bindex) do
key = :ets.first(local_bindex)
[{key, head}] = :ets.lookup(local_bindex, key)
[{key, head}] = find_first_local_bindex_entry(local_bindex)
if head.number > 0 do
[[currency]] =
......@@ -135,6 +134,25 @@ defmodule Index.Augmentation do
end
end
## BR_G12
def unitBaseBR_G12(global_bindex, local_bindex) do
[{key, head}] = find_first_local_bindex_entry(local_bindex)
if head.number == 0 do
:ets.insert(local_bindex, {key, Map.merge(head, %{unitBase: 0})})
else
[[unitBase]] =
:dets.match(global_bindex, {:_, %{number: head.number - 1, unitBase: :"$1"}})
:ets.insert(local_bindex, {key, Map.merge(head, %{unitBase: unitBase})})
end
end
def find_first_local_bindex_entry(local_bindex) do
key = :ets.first(local_bindex)
:ets.lookup(local_bindex, key)
end
def membersCount(local_iindex, global_bindex, local_bindex) do
key = :ets.first(local_bindex)
[{key, head}] = :ets.lookup(local_bindex, key)
......
defmodule Block.Augmentation.Head.UnitBaseTest do
use ExUnit.Case
doctest Index.Augmentation.BIndex
setup_all do
# create a local_bindex table
local_bindex = :ets.new(:local_bindex, [:set, :protected])
:ets.insert(local_bindex, {0, %{number: 0}})
# create an empty global_bindex table
:file.delete("test/global_bindex")
{:ok, global_bindex} = :dets.open_file(:"test/global_bindex", type: :set)
Index.Augmentation.BIndex.unitBaseBR_G12(global_bindex, local_bindex)
[{0, head}] = :ets.lookup(local_bindex, 0)
unit_base0 = head.unitBase
:ets.insert(local_bindex, {0, %{number: 1}})
:dets.insert(global_bindex, {0, %{number: 0, unitBase: 5}})
Index.Augmentation.BIndex.unitBaseBR_G12(global_bindex, local_bindex)
[{0, head}] = :ets.lookup(local_bindex, 0)
unit_base1 = head.unitBase
:dets.close(global_bindex)
:file.delete("test/global_bindex")
{:ok, unit_base0: unit_base0, unit_base1: unit_base1}
end
test "check unitBase BR_G12", state do
assert state.unit_base0 == 0
assert state.unit_base1 == 5
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment