Skip to main content
7 votes
Accepted

Fast unpack of SAM flag bitfield to named symbols

I would prefer an implementation that is simple, built-in, type-safe, and explicit (the original implementation is arguably explicit, but not simple or type-safe; and whereas it does use built-ins it ...
Reinderien's user avatar
  • 62.5k
6 votes
Accepted

Set implementation

Adding entries causes the allocation to grow, but removing entries will never cause it to shrink. The supporting documentation on this submission is inadequate. Its three bullet points are a design ...
J_H's user avatar
  • 29.3k
6 votes
Accepted

C# console app that computes the Jaccard Index

Bug Your logic is flawed when computing the union of the sets: it doesn't include data from set1 in the union of sets. This leads to incorrect results in many cases....
gazoh's user avatar
  • 3,269
6 votes

C# console app that computes the Jaccard Index

It looks to me like your code is wrong: set2.UnionWith(set2); // set2 unioned with itself is a no-op. The fact that HashSet ...
RobH's user avatar
  • 17k
5 votes
Accepted

Optimizing Perfect Hash Table Implementation in C for Improved Performance

Enable more compiler warnings: ...
Harith's user avatar
  • 9,038
5 votes

Fast unpack of SAM flag bitfield to named symbols

There are 2^F possible flag configurations, where F is the number of fields. You can precompute each configuration and store the ...
Justin Chang's user avatar
5 votes
Accepted

Map constructor utility class in Java 8

I don't see why you sould want to throw an IllegalArgumentException when the error case is actually a literal ClassCastException....
TorbenPutkonen's user avatar
5 votes

Saving multiple files in python

Is it worth it to write a function for two lines of code? In this case, yes. Are there other approaches / optimisations to make it better / looks nicer ? Yes: use ...
Reinderien's user avatar
  • 62.5k
4 votes

Saving multiple files in python

You can simplify your code by creating a list of tuples where each tuple consists of the filename and the corresponding data, and then looping over the list and performing the operation in a loop like ...
Harith's user avatar
  • 9,038
4 votes
Accepted

Simple hash table written in C with REPL

Unnecessary casts You cast a lot of value unnecessarily, sometimes even to the type they already have! Casting should only be done if really necessary. Some things that don't need casting: ...
G. Sliepen's user avatar
  • 58.3k
4 votes
Accepted

Dictionary additional function implementations

As @FMc already commented, your method __add__() assumes that both dicts have the same keys at the same positions, which is a very bold assumption. Furthermore, the ...
Richard Neumann's user avatar
4 votes

Program that brute forces to find the minimum dominating set

This ended up being a bit too long for a comment, but I wanted to present another avenue of attack that may result in better performance. The dominating set problem can be easily formulated as an ...
Dair's user avatar
  • 5,906
4 votes
Accepted

A hierarchical dictionary for dotnet

This is a nice implementation. Its written in a way that it is easy to read and understand. That being said, let's face some issues :-) ...
Heslacher's user avatar
  • 50.4k
3 votes

A hierarchical dictionary for dotnet

Would you not be able to do the same with LINQ, SelectMany, and then asking if an a reference comparer to all results from your select many? The only issue I can see with this is, you either need to ...
Morten Bork's user avatar
3 votes

Making a generic NSMapTable replacement written in Swift thread-safe

I appreciate that this is an old question, but a few thoughts. First, I might advise updating SynchronizedValue with modern GCD API. For example: ...
Rob's user avatar
  • 2,552
3 votes

Program that brute forces to find the minimum dominating set

magic numbers ...
J_H's user avatar
  • 29.3k
3 votes

Map constructor utility class in Java 8

Not a fan of hacking compile-time type-safety, so I'm just going to mention an alternative. Pair class is a classic, you can find it in most libraries like ...
Shadov's user avatar
  • 141
2 votes

Program that brute forces to find the minimum dominating set

How to make brute force code more efficient Currently the combinations pre-generates all combinations of size k, creating a lot ...
user555045's user avatar
  • 9,994
2 votes

Given two sparse vectors, compute their dot product

Questions: I have written the following code using Hashmap to calculate the dot product for sparse vectors. Compared to using an array, this method seems faster. But I want to get some opinions on ...
user282248's user avatar
2 votes

Given two sparse vectors, compute their dot product

Partly this depends on how sparse the vectors truly are. Obviously, for extremely dense vectors the array method will be faster, and for extremely sparse vectors the map method will be faster; the ...
Reinderien's user avatar
  • 62.5k
1 vote

Multiple key swap algorithm

You describe this as "key swap", but I suggest that you think of it as "key remapping". approach When I physically reorder my sheets I suggest you think in terms of logically ...
J_H's user avatar
  • 29.3k
1 vote

Dictionary additional function implementations

Interesting class. What motivated it? You might come up with some more descriptive name than BetterDict, perhaps a name drawn from the business domain that ...
J_H's user avatar
  • 29.3k
1 vote
Accepted

Implemented a basic dictionary in python using lists as linked list and murmur hash as a hash function

cite your references from random_things import string_generator What is the meaning of this? We need a # comment in the source ...
J_H's user avatar
  • 29.3k
1 vote

An immutable class that contains Dictionary properties and needs a distinct hash code based on those Dictionaries

Use SortedDictionary to replace .Order() Since you sort the keys of both dictionaries to calculate the hashcode of a ...
t3chb0t's user avatar
  • 44.3k

Only top scored, non community-wiki answers of a minimum length are eligible