Jump to content
  • Advertisement
Sign in to follow this  
Daniel Miller

[.net] std::map equivalent

This topic is 4876 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
In .NET 1.x:
System.Collections.Hashtable

Added in .NET 2.0:
System.Collections.Generic.Dictionnary<K, T>

Look it up.
jods

Share this post


Link to post
Share on other sites
I don't think a hastable would work, because I am working with value types for the keys. I had some trouble getting it working, but maybe that is because of something else that I did wrong.

Generic Dictionary: I cannot use 2.0, but thank you all the same .

Share this post


Link to post
Share on other sites
I think I am right. Look at this:


using System;

namespace Testing
{
struct Point
{
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
public int x;
public int y;
}
public class MainClass
{
public static void Main()
{

Point p1 = new Point (10, 10);
Point p2 = new Point (10, 20); // Note the 20

Console.WriteLine(p1.GetHashCode() + " " + p2.GetHashCode());
}
}
}




The output is "10 10", so I don't think it could be used correctly with a HashTable.

Share this post


Link to post
Share on other sites
I really don't see a problem. Just override GetHashCode(). I never noticed a problem using Hashtable (aside from the fact you have to box/unbox) on value types.

Share this post


Link to post
Share on other sites
Meh, I don't want to go through the trouble of that for what I am trying to do (how lazy can a guy be? :P). I think I will just simulate what I am trying to do by using two parallel ArrayLists.

Share this post


Link to post
Share on other sites
Nope, my last idea won't work.

What I am trying to do related to A*.

I want to check to see if one of my open nodes shares the same coords as the current node which I am going to add to the open list. I guess I will have to loop throught it.

Share this post


Link to post
Share on other sites
Then just use a sorted list of points and use Contains(). (And you don't have to write your own Point class as .NET already has it.)

Share this post


Link to post
Share on other sites
Thanks, there is a point class! It's in System.Drawing, so when I convert this to GDI I'll use it. As of now, I don't know how use the namespace (intellisense can't find it).

I could use a sorted list, but then the values wouldn't be sorted (and I need them to be able to). I think my way will work fine (using a foreach), but if it doesn't I will try your method.

Again, thank you for your time.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!