mkaput / elixir-bimap Goto Github PK
View Code? Open in Web Editor NEWElixir implementation of bidirectional map and multimap
License: MIT License
Elixir implementation of bidirectional map and multimap
License: MIT License
If you try to use bimap 1.0.0, the following warnings are shown during compilation:
==> bimap
Compiling 2 files (.ex)
warning: function slice/1 required by protocol Enumerable is not implemented (in module Enumerable.BiMap)
lib/bimap.ex:465
warning: function slice/1 required by protocol Enumerable is not implemented (in module Enumerable.BiMultiMap)
lib/bimultimap.ex:544
Generated bimap app
When BiMap is used as a module attribute, e.g.
defmodule Example do
@attr BiMap.new(%{1 => :a})
end
the dialyzer complains about the use of opaque type. Although it is correct (if both the implementation of new
and the internal representation change, until recompilation the beam file will contain the old representation) it hinders the usability.
One way to solve that would be to follow Elixir's steps with MapSet elixir-lang/elixir#11917 making the top-level struct keys public and limit "opaqueness" to the values. WDYT about it?
1) property it puts items into bimaps (BiMapPropertiesTest)
test/bimap_properties_test.exs:56
Failed with generated values (after 2 successful runs):
* Clause: key_set <- nonempty(uniq_list_of(term()))
Generated: [%{false => -0.5, #Reference<0.0.1.69648> => "}", "" => -1}, {:N2}]
* Clause: value_set <- uniq_list_of(term(), length: Enum.count(key_set))
Generated: [7.5, -1]
* Clause: random_key <- term()
Generated: 9.0
* Clause: random_value <- term()
Generated: -1.0
Expected truthy, got false
code: assert BiMap.equal?(put_bimap, BiMap.new(put_regular_map))
stacktrace:
test/bimap_properties_test.exs:72: anonymous fn/5 in BiMapPropertiesTest."property it puts items into bimaps"/1
(stream_data) lib/stream_data.ex:2148: StreamData.shrink_failure/6
(stream_data) lib/stream_data.ex:2108: StreamData.check_all/7
test/bimap_properties_test.exs:57: (test)
ref: https://travis-ci.com/github/mkaput/elixir-bimap/jobs/493002978
When inserting a key/value pair into a BiMap where the key and value are already defined, the updated BiMap leaves old mappings in place, and thus the BiMap is no longer bijective. An example is below:
iex(1)> m = BiMap.new([a: 1, b: 2])
#BiMap<[a: 1, b: 2]>
iex(2)> test = BiMap.put(m, :a, 2)
#BiMap<[a: 2, b: 2]>
iex(3)> BiMap.size(m)
2
iex(4)> BiMap.size(test)
2 # Wouldn't this be 1?
iex(5)> BiMap.left(m)
%{a: 1, b: 2}
iex(6)> BiMap.left(test)
%{a: 2, b: 2}
iex(7)> BiMap.right(m)
%{1 => :a, 2 => :b}
iex(8)> BiMap.right(test)
%{1 => :a, 2 => :a}
iex(9)> BiMap.fetch_key(test, 1)
{:ok, :a}
iex(10)> BiMap.fetch_key(test, 2)
{:ok, :a}
iex(11)> BiMap.get(test, :a)
2
iex(12)> BiMap.get(test, :b)
2
In this example, the size of the map should be reduced from 2 elements to 1 element. I suspect that the old mappings should be dropped from the internal maps before updating.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.