Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7720219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:36:56+00:00 2026-06-01T03:36:56+00:00

I have class Vertex{ Graph _graph; float x; float y; string key; //and some

  • 0

I have

class Vertex{
    Graph _graph;
    float x;
    float y;
    string key;
    //and some similar atributes
    public IEnumerable<Edge> Edges{
        get{
            return _graph.Edges.Where(s => s.Source == this);
        }
    }
}
class Edge{
    Graph _graph;
    Vertex source;
    Vertex target;
}
class Graph
{
    private VertexCollection _vertexCollection; // extends List<Vertex>
    private EdgeCollection _edgeCollection; //extends List<Edge>
    public IEnumerable<Vertex> Vertexes
    {
        get
        {
            return _vertexCollection;
        }
    }
    public IEnumerable<Edge> Edges
    {
        get
        {
            return _edgeCollection;
        }
    }
    public IDictionary<Edge, bool> DrawableEdges
    {
        get
        {
            //want to return my uniq dictionary
        }
    }    

Edges and Vertexes are collected into lists

Some example:

A-->B // edge from vertex A to B
B-->C // edge from vertex B to C
C-->A // edge from vertex C to A
A-->C // edge from vertex A to C  -- this is two way edge

So I would like to make IDictionary<Edge, bool> which would hold edges (A–>B and B–>A would be like 1), and bool – if it is two way or no.

I need it because when I draw them now, it draws 2 arrows under one another. I would better make 1 arrow.

So I’m pretty stuck right here… May anybody help me a bit ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:36:57+00:00Added an answer on June 1, 2026 at 3:36 am

    I think you should implement the IEquatable interface for your Edge class:

    public class Edge : IEquatable<Edge>
    {
        ...
    
        public bool Equals(Edge other)
        {
            return (
                (other.Source == this.Source && other.Target == this.Target) ||
                (other.Target == this.Source && other.Source == this.Target));
        }
    
        public override int GetHashCode()
        {
            return (Source.GetHashCode() ^ Target.GetHashCode());
        }
    }
    

    and add your edges to a HashSet<Edge> collection. Then you can call its Contains method to check if it contains the edge or not.

    EDIT: like Henk said, you can also implement a custom IEqualityComparer class:

    public sealed class EdgeComparer : IEqualityComparer<Edge>
    {
        public static EdgeComparer Default { get; private set; }
    
        static EdgeComparer()
        {
            Default = new EdgeComparer();
        }
    
        private EdgeComparer()
        {
        }
    
        public bool Equals(Edge x, Edge y)
        {
            return (
                (x.Source == y.Source && x.Target == y.Target) ||
                (x.Target == y.Source && x.Source == y.Target));
        }
    
        public int GetHashCode(Edge edge)
        {
            return (edge.Source.GetHashCode() ^ edge.Target.GetHashCode());
        }
    }
    

    and initialize your hashset with

    _drawableEdges = new HashSet<Edge>(EdgeComparer.Default);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that represents undirected edges in a graph. Every edge has
I have the following classes: class Vertex { public: float X; float Y; float
Given a Vertex as: class VertexProps { public: int id; float frame; string name;
Say I have some situation like this: class Vertex { public: Position position; Normal
I have Vertex template in vertex.h. From my graph.h: 20 template<class edgeDecor, class vertexDecor,
I am making a basic graph representation in Scala. abstract class Vertex class Edge
I have the following class: public class Vertex() { private double xCoord; private double
Hi I have a boost graph like: struct Vertex; struct Edge; typedef boost::adjacency_list<boost::vecS, boost::vecS,
I have defined a 'vertex' class which, when combined, form a graph. these vertices
I have a class Vertex and a class Graph to draw a graph. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.