An opinion on naming
-
From the top of my head.
public static T GetAtIndex(this Queue queue, int index)
{
T obj = default(T);
int count = queue.Count;
for (int i = 0; i < count; i += 1)
{
T temp = queue.Dequeue();
if (i == index)
{
obj = temp;
}
queue.Enqueue(temp);
}
return obj;
}I'm pretty sure that's how Microsoft intended it :D It's lightning fast if you have only a few items and you don't do it too often :laugh: Or you could do whatever you're doing an name it
IndexedQueue
, like Greg also suggested.Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
That reorders the queue. I can't have my indexing have side effects. If I didn't have to worry about that your solution would be a decent one.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
-
That reorders the queue. I can't have my indexing have side effects. If I didn't have to worry about that your solution would be a decent one.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
No it doesn't, you're simply dequeueing and requeueing everything, effectively ending up with the same queue. The only thing you do is grab the value when you hit the specified index ;)
honey the codewitch wrote:
your solution would be a decent one
NO IT'S NOT! It's de/requeueing EVERYTHING! X| I think Marc's reflection solution would be a better and faster one :laugh: It's also not thread safe, very thread unsafe even. You probably only thought it was decent because it was so beautifully written and formatted :rolleyes:
Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
-
No it doesn't, you're simply dequeueing and requeueing everything, effectively ending up with the same queue. The only thing you do is grab the value when you hit the specified index ;)
honey the codewitch wrote:
your solution would be a decent one
NO IT'S NOT! It's de/requeueing EVERYTHING! X| I think Marc's reflection solution would be a better and faster one :laugh: It's also not thread safe, very thread unsafe even. You probably only thought it was decent because it was so beautifully written and formatted :rolleyes:
Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
I misread your code. I thought you were just enumerating until you found the item. Anyway, I'm not sure that would be faster. See based on what I know from the reference source, there's no reallocations taking place with your technique. It's just setting array elements and incrementing some integers. Reflection can be kinda nasty. I'd have to profile. It definitely depends on the number of items in the queue as well, but for what I'm currently using it for, it shouldn't be more than a half dozen to a couple dozen items.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
-
I misread your code. I thought you were just enumerating until you found the item. Anyway, I'm not sure that would be faster. See based on what I know from the reference source, there's no reallocations taking place with your technique. It's just setting array elements and incrementing some integers. Reflection can be kinda nasty. I'd have to profile. It definitely depends on the number of items in the queue as well, but for what I'm currently using it for, it shouldn't be more than a half dozen to a couple dozen items.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
honey the codewitch wrote:
I thought you were just enumerating until you found the item.
That... Would be a lot easier, but I wasn't aiming for easy :D I also think the internal array doesn't shrink and regrow, so the impact shouldn't be too big. Internally, it keeps track of the head and the tail and wraps to 0 if the last index is occupied, but the array isn't full (it places the items in order when it does need to grow). Still, writing a wrapper, what you no doubt did, and keeping an internal array that you can use... Consumes twice the memory :~ Why the heck is my code a lot better than I originally thought :confused: Feel free to use it (at your own risk) :D Although I still think looping would be a bit faster, if only because you can break at the index.
Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
-
honey the codewitch wrote:
I thought you were just enumerating until you found the item.
That... Would be a lot easier, but I wasn't aiming for easy :D I also think the internal array doesn't shrink and regrow, so the impact shouldn't be too big. Internally, it keeps track of the head and the tail and wraps to 0 if the last index is occupied, but the array isn't full (it places the items in order when it does need to grow). Still, writing a wrapper, what you no doubt did, and keeping an internal array that you can use... Consumes twice the memory :~ Why the heck is my code a lot better than I originally thought :confused: Feel free to use it (at your own risk) :D Although I still think looping would be a bit faster, if only because you can break at the index.
Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
I did not wrap the queue. I implemented my own queue over an array, wrapping like Microsoft's class does.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
-
I did not wrap the queue. I implemented my own queue over an array, wrapping like Microsoft's class does.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
Yeah, that really seems the best, and most labor and time intensive method, for something so easy that could've been there at no extra effort :sigh:
Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
-
Yeah, that really seems the best, and most labor and time intensive method, for something so easy that could've been there at no extra effort :sigh:
Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
LOL, blame microsoft. I really shouldn't have had to reinvent the wheel here.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
-
I need a replacement for Microsoft's Queue that allows for efficient indexed access to the items therein. So I made one. The trouble is, I don't know what to name it. By default, containers in .NET are implemented on arrays (like mine is) so since .NET 2.0 things like ArrayList have simply become (Implied Array)List - indicating array storage unless otherwise specified or there is no default array storage implementation (like with binary trees). The reason this comes up is because of things like LinkedList So while I'd name mine ArrayQueue that itself is inconsistent with microsoft's naming conventions post 1.x Queue itself conflicts but it's what it's currently named. I've made the interface compatible but put it under a different namespace. I'm kind of leaning toward this. Another option I considered was ListQueue because it provides indexed access, but that doesn't really jibe with microsoft's naming conventions either. To be honest, I wish Microsoft would have simply exposed the internal method they have in the reference source in order to provide indexed access. Seems silly that they didn't, since queues are ordered by definition, but whatever.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
"... but that doesn't really jibe with microsoft's naming conventions either." That is of zero concern for me. I couldn't care less what their conventions are. Mostly because I detest what they have done with the Win32 SDK names of structures and members. I'll use what ever convention(s) I feel like using. Here's one example : they continue to use this long pointer prefixing "LP..." on things. We haven't had to deal with long pointers since the 32-bit SDK came into being. The whole large-model programming thing was horrendous and I resent being reminded of it. For this reason, I never, ever use a LP prefix for anything. For the items I access that have to use it I always make a typedef to avoid it.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
-
"... but that doesn't really jibe with microsoft's naming conventions either." That is of zero concern for me. I couldn't care less what their conventions are. Mostly because I detest what they have done with the Win32 SDK names of structures and members. I'll use what ever convention(s) I feel like using. Here's one example : they continue to use this long pointer prefixing "LP..." on things. We haven't had to deal with long pointers since the 32-bit SDK came into being. The whole large-model programming thing was horrendous and I resent being reminded of it. For this reason, I never, ever use a LP prefix for anything. For the items I access that have to use it I always make a typedef to avoid it.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
Well they're of concern to me, which is why I brought them up. And as far as Win32 goes, it's not .NET where naming is concerned. Entirely different ballgame.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
-
I need a replacement for Microsoft's Queue that allows for efficient indexed access to the items therein. So I made one. The trouble is, I don't know what to name it. By default, containers in .NET are implemented on arrays (like mine is) so since .NET 2.0 things like ArrayList have simply become (Implied Array)List - indicating array storage unless otherwise specified or there is no default array storage implementation (like with binary trees). The reason this comes up is because of things like LinkedList So while I'd name mine ArrayQueue that itself is inconsistent with microsoft's naming conventions post 1.x Queue itself conflicts but it's what it's currently named. I've made the interface compatible but put it under a different namespace. I'm kind of leaning toward this. Another option I considered was ListQueue because it provides indexed access, but that doesn't really jibe with microsoft's naming conventions either. To be honest, I wish Microsoft would have simply exposed the internal method they have in the reference source in order to provide indexed access. Seems silly that they didn't, since queues are ordered by definition, but whatever.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
-
Well they're of concern to me, which is why I brought them up. And as far as Win32 goes, it's not .NET where naming is concerned. Entirely different ballgame.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
Yes, I know those are different things, but my point is/was microsoft has changed directions with naming conventions so many times that I can't care less about conforming to their standards.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
-
Yes, I know those are different things, but my point is/was microsoft has changed directions with naming conventions so many times that I can't care less about conforming to their standards.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
I can totally understand that. I'm a little more forgiving I guess. Or I just see different naming patterns to be appropriate in different contexts - I switch up myself. In fact, in C++ I have a few different naming and coding styles and conventions I use depending on the particular "realm" I'm coding in. Different languages, different conventions, too. But that's me. To each their own.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.