Coder Social home page Coder Social logo

Comments (5)

mraleph avatar mraleph commented on August 24, 2024 1

@rebaz94 Dart does not require String instances to be globally canonicalized (with some exceptions around compile time constants). This means two strings can be equal but not identical (because they are represented by different objects).

Simple example:

void main() {
  final s0 = 'key1';
  final s1 = 'key1,key2'.split(',').first;
  print(s0 == s1);
  print(identical(s0, s1));
}

This means using LinkedHashMap<String, ...>.identity() is not a good idea (it is a map which uses key identity rather than equality) unless you somehow ensure canonicalization (e.g. you have another Map<String, String> somewhere which stores canonical instances).

from sdk.

lrhn avatar lrhn commented on August 24, 2024

Edit: Ah, it was a movie, not a picture. Makes more sense now.

That does look suspicious, almost as if the hash table has been built using the wrong hash numbers.
(That said, a Map's keys.contains should work exactly the same as containsKey, so getting a different result is itself a sign of something not being correct. Quoting the keys documentation:

The returned iterable has efficient length and contains operations, based on length and containsKey of the map.

So something is off.)

from sdk.

rebaz94 avatar rebaz94 commented on August 24, 2024

sorry for bad example, This code snippet just an example how I utilized the map. please check the video

final LinkedHashMap<String, dynamic> data = LinkedHashMap.identity();
print(data['key1']); // returns null
print(data.containsKey('key1')); // returns false
print(data.keys.contains(id)); // returns true

from sdk.

rebaz94 avatar rebaz94 commented on August 24, 2024

Ah, got it. Thank you for the clarification.

from sdk.

lrhn avatar lrhn commented on August 24, 2024

I'm still worried that .keys.contains does not answer the same as .containsKey. That suggests that .keys.contains is probably also not efficient. The documentation for keys states that it must have efficient contains (fx. backed by the map's containsKey.)

from sdk.

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.