Note that there are some explanatory texts on larger screens.

plurals
  1. POmake_heap not making heaps
    primarykey
    data
    text
    <p>I have a program that heapsorts a subset of another vector in a vector, as references to indices.</p> <pre><code>std::vector&lt;foo&gt; knowledgeBase; std::vector&lt;int&gt; workingSet; </code></pre> <p>Does this comparison class work?</p> <pre><code>class Compare { bool operator()(int lft, int rgt) { return knowledgeBase[lft].bar() &gt; knowledgeBase[rgt].bar(); } }; </code></pre> <p>Compare is a nested class within the class that contains knowledgeBase, so I have access to the variables, but the index referring to the smallest value is never returned by workingSet.front();</p> <p>What am I doing wrong? I can post more code if required, (which has further, unrelated bugs that I can't test for because this doesn't work) but I know for certain that my make_heap is not creating the heap that I want.</p> <p>In case I'm doing something really stupid, my make_heap call is as follows:</p> <pre><code>std::make_heap(workingSet.begin(), workingSet.end(), Compare()); </code></pre> <p>Edit: bar is size() of a std::set internal to foo. This set is not empty, nor is it undefined, because I can output its contents (and verify them as correct). Though that is using an iterator... is that not sufficient?</p> <p>Edit2: Upon further research, I found that bar() was always returning 1. I added an int, and incremented that every time I added a variable, like so...</p> <pre><code>foo::foo() { siz = 0; } void foo::addLiteral(std::string var, bool truth) { literals.insert(Literal(var,truth)); ++siz; } class foo() { public: foo(); void addLiteral(std::string var, bool truth); bool bar(){return siz;} private: int siz; std::set&lt;Literal, LiteralComp&gt; literals; } </code></pre> <p>foo is initialized like so:</p> <pre><code>... foo newClause; ss.str(input); ss &gt;&gt; variable; while(!ss.fail()) { if(variable[0] == '~') { variable = variable.substr(1); truth = false; } else truth = true; newClause.addLiteral(variable, truth); ss &gt;&gt; variable; } knowledgeBase.push_back(newClause); workingSet.push_back(count++); ... </code></pre> <p>And <code>foo.size()</code> still always returns 1.</p> <p>What is going on?</p> <p>I realize this is far out of the scope of my main question, and there are pieces not defined in the code I've given, but I've been working at this problem for six or so hours now and still have no idea what's going on. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload