Giter Site home page Giter Site logo

Comments (3)

jtmueller avatar jtmueller commented on June 20, 2024

@Wixred just to be clear, when indexing in to a stack, would you expect stack[0] to return the same element that would be returned by stack.Peek() (the most-recently-added element) and stack[stack.Count - 1] (or stack[^1]) to return the first element that was added to the stack?

Also, if we're adding an Insert method, should there also be a RemoveAt method and an IndexOf method? Should we just go ahead and implement all of ICollection<T>? Where do we draw the line?

from collections.pooled.

Wixred avatar Wixred commented on June 20, 2024

The thought was the index is a simple wrapper around the underlying array indexer. But you're right, where do you draw the line with this functionality.

from collections.pooled.

jtmueller avatar jtmueller commented on June 20, 2024

I'm not necessarily opposed to making the class indexable, I'm just not sure of the semantics. Internally items are stored with the most-recently-added item as the last item in the internal array, and calling Peek/Pop returns the last item (but in Stack semantics, it's the first item). So the actual implementation for the indexer would need to return the value at something like Count - i to give you what I think is probably the most intuitive output.

I'm a little less sanguine about the Insert method. You've got the same "what does the index value actually mean" issue, plus the "where do you draw the line" issue, and I'm not sure if the added functionality would be worth it.

from collections.pooled.

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.