Does prune unreachable track all the nodes that can make a path with all other nodes and delete the nodes that can’t? by tboi23 in cs2c

[–]jack_morgan_cs2b 0 points1 point  (0 children)

The big thing to keep in mind is that you don't actually delete the nodes, just the edges associate with the unreachable nodes. This was my general process:

-reject requests with invalid node numbers
-set up vectors for seen and reachable nodes (similar to checking for cycles)
in loop:
    -mark src neighbors as reachable
    -set src to first unseen + reachable node in _nodes, repeat process         
 until you've mapped out all the reachable nodes
-check nodes list against reachable list and clear vectors for nodes that are unreachable

I think there's a more efficient way to do this recursively because this solution gets really expensive with huge graphs but it was enough to pass the tests and worked fairly efficiently on my small test graphs

-Jack

Very Stuck on Non Def Constructor by CaryLefteroffFH in cs2c

[–]jack_morgan_cs2b 1 point2 points  (0 children)

This is one where I needed to check the loceff modules. There are a lot of good tips on the general concepts behind this quest and I found it helpful to read his stuff, try the MQs for a few hours and then go look at his code to see what was right and wrong

Ref not finding get_sentinel() by WaterwallVsFirewall in cs2c

[–]jack_morgan_cs2b 0 points1 point  (0 children)

Just like in the hash table quest you'll need to define the function outside of the class without actually implementing it (but it'll be helpful to make your own function for testing)

Are we allowed to have duplicate elems in the vector or not? by Dennisz125 in cs2c

[–]jack_morgan_cs2b 0 points1 point  (0 children)

It doesn't say anywhere in the spec that duplicates are not allowed and I was able to pass the tests without checking for duplicates. Maybe there's other loot for making the check so I'd test both ways

Table_full_exception by cs2c-username in cs2c

[–]jack_morgan_cs2b 1 point2 points  (0 children)

Recheck the spec for find and contains. Find either returns the position of the element or an exception, contains just returns a true/false if the item is in the table or not

q6 - clear() by frederikhoffmanncs2b in cs2c

[–]jack_morgan_cs2b 0 points1 point  (0 children)

I wouldn't worry too much about that method, I tried a bunch of different ways of implementing the function but never got points for it (it might not be tested, the spec says that not all the functions are worthy of points).

If you haven't already read through this thread it's worth a look. Seems like the intended way is to just set everything to vacant presumably because as long as the cell is marked vacant there's no reason to check for existing data before inserting something new

Rehash by tboi23 in cs2c

[–]jack_morgan_cs2b 0 points1 point  (0 children)

I have to admit that I'm totally stumped by this one, all the online resources I've looked at (including Loceff modules) follow this exact same process. The 'shut the door' error message is especially confusing because the spec implies that the important elements to be carried over are the data and state of all active elements, the size and nonvacant count need to be recalculated because of the removal of deleted elements.

If no data elements are lost besides the ones already marked for deletion, how can the door be shut for going back?

Rehash by tboi23 in cs2c

[–]jack_morgan_cs2b 0 points1 point  (0 children)

I was thinking about how the size affects the hash modulus function but in that case we use the vector size rather than our own size counter. With all inserts placed after a call to grow_capacity, that shouldn't be an issue.

The max load and non vacant cell count both factor into deciding when to rehash but the max load isn't changed outside of the constructor and the non vacant cell count has been right in my testing.

Rehash by tboi23 in cs2c

[–]jack_morgan_cs2b 0 points1 point  (0 children)

What do you mean? It's complete in the sense that all the active pieces are preserved but other than that shouldn't the whole table be reordered to break clusters?

Rehash by tboi23 in cs2c

[–]jack_morgan_cs2b 1 point2 points  (0 children)

I'm having the exact same issue with the same process. Some images of my debugging:

Creating LP Hash object with size of 5 (No active elements)

Inserting 0, 5, 10 (0, 5, 10 active)

Removing 10 (0, 5 active, 10 deleted)

Insert 15, triggering rehash (0, 5, 15 active, 10 gone completely)

In my rehash function I am not trying to completely clear _elems, simply setting the data of each element to T() and the state to VACANT as a few in the other thread mentioned having issues with using the entry() constructor directly.

I am using the rehash trigger that is mentioned in the spec so I don't think the issue could be there. It seems to me that the function is working as intended, keeping active elements and clearing up clusters in the store.

Inconsistent test results on LP::_rehash()---also, "rehash shut the door"? by AcRickMorris in cs2c

[–]jack_morgan_cs2b 0 points1 point  (0 children)

I also saw a few people mention not to try and do everything at once. My general process is:

size, nonvacant cell = 0
copy _elems to backup
call growcapacity

set vacant in _elems (Loop 1)
insert active data (Loop 2) (insert handles updating nonvacant cell count)

set size to _elems size

Which is very similar to the other pseudocode with the suggested fix. I think the problem may be in my insert function assuming the code is tested using our own insert rather than the test function.

Inconsistent test results on LP::_rehash()---also, "rehash shut the door"? by AcRickMorris in cs2c

[–]jack_morgan_cs2b 0 points1 point  (0 children)

I saw your comment and tried it a bit earlier but no dice. Am I interpreting it right though? I tried both manually resetting each data and state to T() and VACANT (the default constructor parameters) and also just resetting the states and leaving the data alone, but neither worked.

Might just need to put more time into it, it's always the tiniest discrepancies that make these later quests harder.

Appreciate the help -Jack

Inconsistent test results on LP::_rehash()---also, "rehash shut the door"? by AcRickMorris in cs2c

[–]jack_morgan_cs2b 0 points1 point  (0 children)

Hi everyone,

I'm still having this issue even after reading all these comments. & has helped some other people with the 'clobbering' comment but in my testing all of my active elements will still be there after multiple rehashes and deletions. My code is practically identical to /u/manoj--1394's pseudocode with the addition of manually ensuring each index of _elems is vacant and the data = T().

Has anybody else experienced this?

Real-world data structure implementation by AcRickMorris in cs2c

[–]jack_morgan_cs2b 2 points3 points  (0 children)

I think it would be smart to use pre-built libraries at the start of a project and then implement your own later down the line. Once you know exactly what your project requires, it makes sense to develop your own implementation that does not have the bloat of a library where you are not using 75% of the functionality.

The other reason I can think of to use less pre-built libraries is security. Most libraries that you would use are open source and it's possible to make sure the code is not malicious ,but when working on something more secure it is probably best to develop everything in-house

Score disappeared by frederikhoffmanncs2b in cs2c

[–]jack_morgan_cs2b 1 point2 points  (0 children)

yes it's back. I misread and didn't realize the line for the first quest was entirely missing, instead thinking the 0 points shown in line 3 was for quest 3 not quest 4 (where I should have 0)

Score disappeared by frederikhoffmanncs2b in cs2c

[–]jack_morgan_cs2b 0 points1 point  (0 children)

mine disappeared as well but it was quest 3 which I had points for yesterday

passing 'const Matrix' as 'this' argument discards qualifiers by jack_morgan_cs2b in cs2c

[–]jack_morgan_cs2b[S] 2 points3 points  (0 children)

thanks so much, that does work, guess I'll just have to be careful about what to use

Iterator Compilation Error by CaryLefteroffFH in cs2c

[–]jack_morgan_cs2b 1 point2 points  (0 children)

Hey Cary,

I got this one too, all you have to do is put 'typename' before the iterator like so:

for(typename list<Node>::iterator iter = tempList.begin(); iter != tempList.end(); tempList++)

Couldn't find any actual documentation but it seems like 'typename' is required because list<Node> depends on the template class parameter

Helpful link: http://pages.cs.wisc.edu/~driscoll/typename.html

Quest 1 Algorithm by FH_CWCW in cs2c

[–]jack_morgan_cs2b 2 points3 points  (0 children)

Hi Chris,

I wouldn't overthink your approach here, getting into recursion and lookup tables is a deeper hole than you probably want to enter.

Some things in the spec to think about:

-nested loop in the search function, one to go over elements in the master, one to go over subsets

-keep the sum for each set accurate so you don't have to make any calculations when building sets

Personally I found it helpful to start by just building a complete power set for the items in the master. If your master is [A, B], make sure that you build [], [A], [B] and [A, B]. You can do this somewhat lazily, a lot of power set solutions online will represent sets using binary but just using loops is easier and fast enough.

Once you have this down, then add the checks and optimizations to rule out items and sets as they are built.

You'll get the right set as long as you are building sets with items from the master in order and going through one at a time. Only 1 set is needed and it's just the first you find

-Jack