text:
Q: When building a hash table using linear probing for collision resolution, is the extra term always added to the hash or only when a collision occurs? I'm building a table, where an attempt to insert a new key into the table when there is a collision follows the sequence { hash(x) + i, where i = 1,2,3, ... }.  If I'm building a hash table using linear probing would my Insert() algorithm do something like this:
hashValue = hash(x)
while hashValue is taken in table
  hashValue += 1

where I only add the increment value when there's a collision, or would I add the increment value to the hash right from the start when i = 1 , so something like this:
hashValue = hash(x) + 1
while hashValue is taken in table
  hashValue += 1

A: As long as you do it consistently, it does not matter. The effect of adding one (or any other constant, for that matter) to hash code has no effect on the composition of the table, except that the bucket numbering would be "shifted off" by a constant "offset". Since bucket numbering is a private matter of your has table, nobody should care.
In essence, a linear probing hash function is
H(x, i) = (H(x) + i) % N

where N is the number of buckets. It is conventional to start i at zero, which means incrementing the value of hash only when you get a collision.

A: It does not hurt (it simply shifts the probe sequence by one element), but it doesn't have any benefits either, and conceptually it's a bit silly. That's why the canonical form starts at hash(x) and increments only when encountering collisions.


text:
Q: Windows Vista - Best way to protect "secret" files from being unseen I live on my computer, so therefore I put a lot of secret information on it (passwords, personal documents, etc.)  I'm concerned that people that are part of my network (at work, or at home) may navigate to my folder structure and see some of these files.
I've foolishly tried removing the "Everyone" Windows security group from seeing my "secret" files (and found out that I myself was part of the "Everyone" group, lol)  What is the best way to hide/protect my files from people navigating to them when I'm connected to a network?

A: I had the same issue, but i found the safest way was to stick all of it on a memory stick and use TrueCrypt to protect it.

A: First, you should be able to add your own account to the security, and then remove Everyone. Do not use the DENY attribute on any group you belong to. You will be back asking how to undo that.
That would probably do 99.99% of the job, if you REALLY want to be safe, you could encrypt your files.

redpajama_set_name: RedPajamaStackExchange


text:
Q: Shorten iterator by condition in rust I'm looking for some way to shorten an iterator by some condition. A bit like an inverse filter but it stops iterating at the first true value. Let's call it until(f). Where:
iterator.until(f)

Would return an iterator that only runs until f is true once.
Let's use an example of finding the next prime number.
We have some structure containing known primes and a function to extend it.
// Structure for caching known prime numbers
struct PrimeGenerator {
    primes:Vec<i64>
}

impl PrimeGenerator {

    // Create a new prime generator
    fn new()->Self{
        let primes = vec![2,3];
        Self {
            primes,
        }
    }

    // Extend the list of known primes by 1
    fn extend_by_one(&mut self){
        let mut next_option = self.primes.last().unwrap()+2;
        while self.primes.iter().any(|x| next_option%x == 0) { // This is the relevant line
            next_option += 2;
        }
        self.primes.push(next_option);
    }

}

Now this snippet is a bit too exhaustive as we should only have to check until the square root of next_option, so I was looking for a some method that would shorten the iterator based on some condition, so I could write something like:
self.iter().until(|x| x*x > next_option).any(|x| next_option%x == 0)

Is there any similar pattern available?

A: Looks like your until is similar to inverted take_while.
self.iter().take_while(|x| x*x <= next_option).all(|x| next_option%x != 0)