Giter VIP home page Giter VIP logo

Comments (7)

tidwall avatar tidwall commented on August 15, 2024

For quick operations a RWMutex is usually good enough.

Is it possible to get a deep copy of the rtree, or some other 'thread safe' access to a fixed view of the tree for searching?

There isn't a deep copy function per se, but the Scan() function is a pretty quick way to retrieve every item in the tree.

items := make([]Item, 0, tr.Len())

mu.RLock()
tr.Scan(function(min, max []float64, item Item) bool {
        items = append(items, item);
        return;
})
mu.RUnlock()

// now 'items' has every item in the tree.

Though that may be too slow if you have a ton of items.

Or is this what the shallow copy actually achieves?

Yes, the Copy() function performs an instant copy using a copy-on-write technique.

mu.Lock()         // write lock needed
tr2 := tr.Copy(). // instant copy
mu.Unlock()

// now 'tr2' is a copy of 'tr'

from rtree.

jfberry avatar jfberry commented on August 15, 2024

I have > 1million items in my tree; and want to use the geo scanning for Scan.
In your second example, can I take tr2 and iterate that (with Scan) without having a threading problem against tr which will be still deleting and inserting values?

from rtree.

jfberry avatar jfberry commented on August 15, 2024

(My Scan operation with my processing to selectively look at the items takes a few thousands milliseconds which is why I wish to try and find the best solution for holding the mutex). It's not the rtree iteration which is slow but my decision making.

from rtree.

tidwall avatar tidwall commented on August 15, 2024

In your second example, can I take tr2 and iterate that (with Scan) without having a threading problem against tr which will be still deleting and inserting values?

Correct. There will be no threading problems.

The Copy() function is more-or-less an instance snapshot of the rtree. So any changes to the original rtree will not be available to the copied rtree, and vice-versa.

The only side-effect is due the nature of copy-on-write, where any changes (writes) to the copy or original will trigger internal copying of the nodes that are changed. But this is usually pretty quick (though not free).

from rtree.

jfberry avatar jfberry commented on August 15, 2024

In your second example, can I take tr2 and iterate that (with Scan) without having a threading problem against tr which will be still deleting and inserting values?

Correct. There will be no threading problems.

The Copy() function is more-or-less an instance snapshot of the rtree. So any changes to the original rtree will not be available to the copied rtree, and vice-versa.

The only side-effect is due the nature of copy-on-write, where any changes (writes) to the copy or original will trigger internal copying of the nodes that are changed. But this is usually pretty quick (though not free).

Ok, I will give that a go :-)

from rtree.

jfberry avatar jfberry commented on August 15, 2024

This appears to be working correctly :-) Thank you for a great library

from rtree.

tidwall avatar tidwall commented on August 15, 2024

You’re welcome and I’m happy to hear it working for you.

from rtree.

Related Issues (6)

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.