Giter Club home page Giter Club logo

Comments (12)

ztellman avatar ztellman commented on September 25, 2024 1

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.

adamretter avatar adamretter commented on September 25, 2024 1

@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.

line-o avatar line-o commented on September 25, 2024

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.

adamretter avatar adamretter commented on September 25, 2024

@line-o The documentation in the README.md states:

LinearMap is a mutable hash-map

from bifurcan.

line-o avatar line-o commented on September 25, 2024

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.

ztellman avatar ztellman commented on September 25, 2024

EDIT: this was in response to a misreading of the original code, apologies

from bifurcan.

ztellman avatar ztellman commented on September 25, 2024

I've released 0.2.0-alpha6

from bifurcan.

line-o avatar line-o commented on September 25, 2024

@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.

ztellman avatar ztellman commented on September 25, 2024

There is an unenforced assumption that once you call forked, you cease to interact with the collection that was forked.

from bifurcan.

line-o avatar line-o commented on September 25, 2024

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.

ztellman avatar ztellman commented on September 25, 2024

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.

line-o avatar line-o commented on September 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.