Questions tagged [count]
6 questions
14
votes
4 answers
Number of Classes in a Namespace - Code Smell?
I have a C# library that's used by several executables. There's only a couple namespaces in the library, and I just noticed that one of the namespaces has quite a few classes in it. I've always avoided having too many classes in a single namespace…

Tim Claason
- 913
- 7
- 11
6
votes
2 answers
Is checking count/size/length less than 0 necessary in modern languages?
Is checking count/size/length less than 0 necessary in modern languages anymore? For instance, in C# I quote often will check if a collection's count is less than or equal to 0.
I assume that this was done in older languages, like C, where you could…

TruthOf42
- 752
- 1
- 7
- 15
3
votes
2 answers
Explanation to why Counting bits set, Brian Kernighan's way works
I found this link to count number of bits in a variable. I think it is pretty cool, but I can't figure out why it works. Can someone offer an explanation?
Here is the code
unsigned int v; // count the number of bits set in v
unsigned int c; // c…

flashburn
- 147
- 1
- 8
2
votes
3 answers
Count unique visitors by group of visited places
I'm facing the problem of counting the unique visitors of groups of places.
Here is the situation:
I have visitors that can visit places. For example, that can be internet users visiting web pages, or customers going to restaurants. A visitor can…

Mathieu
- 980
- 8
- 12
0
votes
4 answers
API design: Should a count() of a set of consecutively-id'ed elements return a size type?
I'm writing C++ code, where the standard library has an idiomatic type for representing sizes: std::size_t.
Now, I'm writing a function which counts certain kinds of objects; and these objects have indices, used as their id's, which start from 0,…

einpoklum
- 2,478
- 1
- 13
- 30
0
votes
3 answers
Frequency distribution by range algorithm
I have an array of unsorted positive real numbers. I need to create a frequency distribution by their ranges.
The simplest approach goes like this
for num in numbers
if (num > 0 and num < 10) a++
elseif (num >= 10 and num < 20) b++
...
else…

Sudhanshu 'Sid' Vishnoi
- 103
- 2