Comments (4)
As to why this is may be important to some people. It is possible that one of
the Index works on a field that is not included in equals(). And this will
cause Index to be not updated but set to be updated, which is an internally
inconsistent state. We should try to minimize such issues.
Original comment by [email protected]
on 8 Nov 2013 at 10:08
from cqengine.
Hi Atul,
This is very interesting.
I've done some digging and I'm not sure that this is an issue. But it looks
like java.util.Collections.newSetFromMap() relies on some very specific
implementation details of Maps.
Based on JDK 8 sources anyway:
http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/f82b730c798b/src/share/classes/jav
a/util/Collections.java
Collections.newSetFromMap(), the add() method is as follows:
public boolean add(E e) { return m.put(e, Boolean.TRUE) == null; }
..it delegates to the map.put(element, Boolean.TRUE) method of the underlying
Map that it wraps. But the element being stored in the Set, is supplied to the
Map as the key, not as the value.
http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/f82b730c798b/src/share/classes/jav
a/util/concurrent/ConcurrentHashMap.java
It looks like the internal putVal() method, is implemented such that even if
put() was called multiple times with several key objects all being equal to
each other, the first key object would be stored in a Node, and subsequent key
objects would never replace it.
At that point I was thinking that these findings were just anecdotal, but then
I also remembered that Map provides methods:
Set<K> keySet()
Collection<V> values()
...so the set of keys in a map might actually be required to implement the Set
contract, which would indeed imply that adding a key a second time should not
replace the existing key, making all Maps compatible with
Collections.newSetFromMap().
It seems that all of this might hinge on a very subtle aspect of the Map
contract, which isn't spelled out explicitly anywhere I can find.
Original comment by [email protected]
on 9 Nov 2013 at 7:49
- Changed state: Accepted
from cqengine.
Yes, you are right, I think it is better to throw away my patch than having
more complex code.
The other optimization it brings is addAll() is faster, because size() is not
considered while checking it. It is possible size() is not O(1) operation, and
sometimes even as bad as O(n) depending on ConcurrentMap implementation we are
talking about.
There is another bug related to remove() and removeAll() which I'll raise on
another issue.
Original comment by [email protected]
on 9 Nov 2013 at 9:15
from cqengine.
Closing this as discussed. Thanks for reporting anyway, they more eyes on the
code the better.
Original comment by [email protected]
on 13 Nov 2013 at 11:33
- Changed state: Invalid
from cqengine.
Related Issues (20)
- FilteringIterator returns hasNext as true after the collection is consumed HOT 1
- Update data automatically HOT 1
- Pagination Over data HOT 4
- Perfomance index HOT 3
- Consider exposing utility static method taking collections
- Reenable cached hashCode
- Support for java.util.Optional
- [Question] How does CQEngine pick the appropriate index to query?
- most longest prefix value exist in the column value but it doesn't intersect with other columns values in the query that we need part of query retrieval HOT 7
- Support STRICT_REPLACEMENT in ObjectLockingIndexedCollection/ConcurrentIndexedCollection
- TransactionalIndexedCollection support for UniqueIndex is broken
- Support for attribute accessors for Java record type HOT 1
- Kryo generates InaccessibleObjectException - Make Dependencies "Java 17 compatible"
- Bug in AttributeOrdersComparator HOT 5
- Offheap cache visibility HOT 1
- Support for ANTLR 4.10.1 HOT 12
- Does it support SQL statistics queries HOT 3
- Thread blocked when using Materialized View Sort For the Longest Prefix for CSV that contain more than 11 K rows HOT 3
- Error while parsing SQL NOT LIKE query HOT 1
- Error while parsing SQL LIKE '%%%' query
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 cqengine.