Comments (12)
This was an extremely indirect result of IntSet.isLinear
always returning false due to it not being properly overridden. I've confirmed that your example now exhibits the correct behavior. Thanks for catching this, I need to give some thought as to properly expose these sorts of issues in my property-based testing.
I'll update the issue once this fix is in a released version.
from bifurcan.
@ztellman Thanks for being so responsive as always Zach, it's much appreciated. Also thanks for the prompt fix, I will upgrade our project to use it.
@line-o I believe that the code as I had it before is still correct, and that this fix resolves the issue we saw.
from bifurcan.
As I understand it
IMap<Integer, Boolean> map1 = new LinearMap<>();
map1.put(1, true);
is immutable as such.
So the below would be the way to mutate a copy/fork:
IMap<Integer, Boolean> map2 = map1.forked(); // create a forked map for modifications
map2 = map2.remove(1);
// doesn't do anything since the map is already forked
// or creates a second forked map
map2 = map2.forked();
from bifurcan.
@line-o The documentation in the README.md states:
LinearMap is a mutable hash-map
from bifurcan.
Yeah my comment from above is misleading. Because LinearMap is mutable it needs to be forked before it is mutated as a fork.
from bifurcan.
EDIT: this was in response to a misreading of the original code, apologies
from bifurcan.
I've released 0.2.0-alpha6
from bifurcan.
@ztellman for me to understand this better:
If I create a map I do not have to call forked()
as long as before a mutation (as in a mutation in my map implementation) first calls forked()
or cloned()
.
Is the above statement correct or would I have to call forked as a way of committing a specific map?
from bifurcan.
There is an unenforced assumption that once you call forked, you cease to interact with the collection that was forked.
from bifurcan.
So it would be more inline with your idea to call clone() on a map once it is exposed?
We use it as the implementation of immutable maps in a functional programming language where a mutating operation will always operate on a copy.
from bifurcan.
While the clone
methods of the Linear*
will create an actual separate block of memory representing the same collection, the same isn't true for their immutable cousins (on reflection, calling clone
on those should probably throw an exception rather than return the same collection).
I'm not sure I understand how you're using the collections, but the default usage should be all immutable collections all the time. If you have a local window in which you're making a bunch of changes, you can make them temporarily linear. If you're never sharing the collection, using the Linear*
collections may be appropriate. The fact that you can call LinearMap.forked()
doesn't mean it's the right thing to do in most cases. If you can provide more details, I might be able to give more specific advice.
from bifurcan.
In that functional language, Xquery, any map is immutable.
So any operation f : map -> map
must return a new map.
How would you implement that using your implementation?
The current implementation you can derive from @adamretter code examples, where each step 1.,2.,3.,... is a statement in Xquery.
from bifurcan.
Related Issues (20)
- concat then slice throws exception with some List instances HOT 2
- Minor: redundant defn of benchmark-iteration in benchmark-test ns
- No documentation about the maximum number of elements that can be stored in a List HOT 1
- Bug - remove fails on VirtualMap HOT 2
- add methods for type-safe creation of empty instances
- AIOOBE on List slice/concat usage HOT 4
- What's in the 0.2.0-alpha2 release? HOT 4
- Iterator is incorrect after remove on Linear Map HOT 3
- Possible NPE in MapNodes#put HOT 5
- timing in clojure gives slower results than clojure's persistent datastructures on inserts HOT 4
- Upscaling/Downscaling between the Bifurcan List and the Clojure Vector
- Possible accidental mutation HOT 1
- Forked set is modified after baked linear set modification HOT 1
- Sliced list cannot be made linear
- Removing nodes from DAGS leaves those nodes in top/bottom
- Graphs.merge doesn't actually merge graphs!
- Graphs with custom eq/hash don't seem to use them
- DAG bottoms seem to include extra vertices
- IntMap.mapValues crashes with a NPE
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bifurcan.