GithubHelp home page GithubHelp logo

Comments (8)

ddur avatar ddur commented on August 15, 2024

To be precise:
I use C5.HashDictionary<K, int>.Values
On second call to Values, all int values are 0 (zero)

from c5.

ondfisk avatar ondfisk commented on August 15, 2024

Could you supply a piece of code to reproduce the bug?
Is the bug present in previous versions?

from c5.

ddur avatar ddur commented on August 15, 2024

Test
Implementation under test
Bug was not present in 2.4.5828.26833

from c5.

ddur avatar ddur commented on August 15, 2024

@ondfisk
Just add two or three Key-Value-Pair (T, int) with different int values.
Get the .Values, everything is OK.
Get the .Values again and all int values are 0.

from c5.

Dana-Ferguson avatar Dana-Ferguson commented on August 15, 2024

I have found the change that caused the issue:

inside: internal class KeysCollection : CollectionValueBase<K>, ICollectionValue<K>
@ Dictionaries.cs

            public override SCG.IEnumerator<V> GetEnumerator()
            {
                //Updatecheck is performed by the pairs enumerator
                foreach (KeyValuePair<K, V> p in pairs)
                    yield return p.Value;
            }

became

            public override SCG.IEnumerator<V> GetEnumerator()
            {
                //Updatecheck is performed by the pairs enumerator
                _internalEnumerator.UpdateReference(_pairs);
                return _internalEnumerator;
            }

The new enumerator:

                internal void UpdateReference(ICollection<KeyValuePair<K, V>> list)
                {
                    _internalList = list;
                    Current = default(V);
                }

                public override bool MoveNext()
                {
                    ICollection<KeyValuePair<K, V>> list = _internalList;

                    if (_internalEnumerator == null)
                        _internalEnumerator = list.GetEnumerator();

                    if (_internalEnumerator.MoveNext())
                    {
                        Current = _internalEnumerator.Current.Value;
                        return true;
                    }

                    Current = default(V);
                    return false;
                }

And within that: (in MoveNext)

                    if (_internalEnumerator == null)
                        _internalEnumerator = list.GetEnumerator();

Is only ever called once and never updated.

if you add _internalEnumerator = list.GetEnumerator(); to UpdateReference, it works again.
I assume that its supposed to be linqy and update automagically, but its not (why this is a comment, and not a PR, I don't understand the intended behavior).

I noticed that the Keys collection resolves differently at runtime. Values uses the ValuesCollection and ValueEnumerator resolving to C5.TreeSet<C5.KeyValuePair<,>.Enumerator (which has the old stamp value of '0'), but Keys resolves to C5.SortedDictionaryBase<, >.SortedKeysCollection.KeyEnumerator. So I assume this bug would also affect Keys if Keys used the KeysCollection in the same way as the Values uses ValuesCollection.

I hope this helps in solving the problem.

from c5.

ondfisk avatar ondfisk commented on August 15, 2024

It certainly does. Thanks.
I will look into it ASAP.
I have hidden the buggy NuGet packages.

from c5.

ddur avatar ddur commented on August 15, 2024

Thanks

from c5.

ondfisk avatar ondfisk commented on August 15, 2024

I've pushed a new version to NuGet. Please verify that the issue has been resolved

from c5.

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.