Beispiel #1
0
 public Sample GetSample(ValueMap letters, int pos_x)
 {
     Sample key = new Sample(SAMPLE_X);
     int x = pos_x - SAMPLE_X + 1;
     for (int i = 0; i < SAMPLE_X; i++)
     {
         if ((x + i) < 0) key.Set(0, i);
         else if ((x + i) >= letters.GetSizeX()) key.Set(GRID_SIZE - 1, i);
         else key.Set(letters.GetValue(x + i, 0), i);
     }
     return key;
 }
Beispiel #2
0
        int GenerateIndex(Sample sample, bool use_size)
        {
            int counter;
            int total, freq, letter;
            int end = (use_size ? 1 : 0);

            // Get the frequencies
            total = 0;
            for (counter = 1; counter < (GRID_SIZE - end); counter++)
            {
                Sample key = new Sample(sample);
                key.Set(counter, (SAMPLE_X - 1));
                total += GetUsageCount(key);
            }

            // Choose a 'target' frequency
            if (total > 0)
            {
                letter = (randgen.NextInt() % total) + 1;
            }
            else
            {
                return -1; // no solution
            }
            // Move through the table until we hit the 'target' frequency
            counter = 1;
            freq = 0;
            do
            {
                Sample key = new Sample(sample);
                key.Set(counter, (SAMPLE_X - 1));
                freq += GetUsageCount(key);
                counter++;
            } while (freq < letter);
            return counter - 1;
        }