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 8197187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:41:26+00:00 2026-06-07T05:41:26+00:00

I have to implement a call graph for expressions like Id = Id(Param); and

  • 0

I have to implement a call graph for expressions like Id = Id(Param); and that wasn’t a problem.

Now I have to implement an enumerator which lists one at a time all topological orderings among the calls that satisfy the order of dependencies.

And here’s the trouble.

This is a simple node for the call graph:

class CallGraphNode
{
    private string name;
    public List<CallGraphNode> dependents = new List<CallGraphNode>();
    public int dependencies;
    private bool executed = false;
    public bool Executable { get { return dependencies == 0; } }
    public bool Executed { get { return executed; } set { executed = value; } }

    public CallGraphNode(string name)
    {
        this.name = name;
        dependencies = 0;    
    }

    public override string ToString()
    {
        return name;
    }

    public void AddDependent(CallGraphNode n)
    {
        dependents.Add(n);
    }          
}

And this is the call graph class itself:

class CallGraph : IEnumerable<List<CallGraphNode>>
{
    public List<CallGraphNode> nodes = new List<CallGraphNode>();

    public void AddNode(CallGraphNode n)
    {
        nodes.Add(n);
    }

    public static void Show(IEnumerable<CallGraphNode> n)
    {
        foreach (CallGraphNode node in n)
        {
            Console.Write("{0} ", node);
        }
        Console.WriteLine();
    }

    static IEnumerable<List<CallGraphNode>> EnumerateFunctions(List<CallGraphNode> executable, List<CallGraphNode> res)
    {
        if (executable.Count == 0)
            yield return res;
        else foreach (CallGraphNode n in executable)
            {
                if (!n.Executed)
                    res.Add(n);
                List<CallGraphNode> next_executable = new List<CallGraphNode>(executable);
                executable.Remove(n);
                foreach (CallGraphNode m in n.dependents)
                    if (--m.dependencies == 0)
                        next_executable.Add(m);
                foreach (List<CallGraphNode> others in EnumerateFunctions(next_executable, res))
                    yield return others;
                foreach (CallGraphNode m in n.dependents)
                    m.dependencies++;
                if (!n.Executed)
                    res.Remove(n);
            }
    }

    IEnumerator<List<CallGraphNode>> IEnumerable<List<CallGraphNode>>.GetEnumerator()
    {
        List<CallGraphNode> executable = new List<CallGraphNode>();
        foreach (CallGraphNode n in nodes)
            if (n.Executable || n.Executed)
                executable.Add(n);
        List<CallGraphNode> output = new List<CallGraphNode>();
        foreach (List<CallGraphNode> list in EnumerateFunctions(executable, output))
            yield return list;
    }

    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
    { throw new NotImplementedException(); }
}

Now, the problem is it just won’t work. When I try to create an IEnumerator and assign it the GetEnumerator() return value, I get a casting error and that’s honestly what I expected when trying to do so:

IEnumerator<List<CallGraphNode>> lt = cg.GetEnumerator();

Then I’ve tried:

System.Collections.Generic.List<CallGraphNode>.Enumerator en = cg.nodes.GetEnumerator();

This works, but the method EnumerateFunctions is never called and the enumerator just contains the original list of graph nodes.

Any ideas?

  • 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-07T05:41:27+00:00Added an answer on June 7, 2026 at 5:41 am

    The problem is that you’re implementing both IEnumerable<T> and IEnumerable using explicit interface implementation.

    You probably want to change this declaration:

    IEnumerator<List<CallGraphNode>> IEnumerable<List<CallGraphNode>>.GetEnumerator()
    

    to be a “normal” interface implementation:

    public IEnumerator<List<CallGraphNode>> GetEnumerator()
    

    Alternatively, you could stick with explicit interface implementation, but use:

    IEnumerable<List<CallGraphNode>> sequence = cg;
    IEnumerator<List<CallGraphNode>> lt = sequence.GetEnumerator();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to implement something like that: ListViews I call month.setadapter(adapter) once for each
I need to implement a call to a method that I have in my
I have a problem that's equal to the one presented here: how to define
I have to implement classes that work with payment system (let's call it PaymentSystem)
I have an object that implements an interface. I want to call on the
I have a WCF service implemented with a call back contract that I am
We implemented new coding standards, which call for our private members to have a
I have implement a scenario which involves two way communication between child and parent
I have to implement a sparse matrix (a matrix that has predominantly zeroes, so
I have a data set which is a large unweighted cyclic graph The cycles

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.