Example #1
0
        private static Bitset[] CreateBitsets(OutputModelFactory factory,
                                              IntervalSet set,
                                              int wordSize,
                                              bool useZeroOffset)
        {
            IList<Bitset> bitsetList = new List<Bitset>();
            foreach (int ttype in set.ToArray())
            {
                Bitset current = bitsetList.Count > 0 ? bitsetList[bitsetList.Count - 1] : null;
                if (current == null || ttype > (current.shift + wordSize - 1))
                {
                    current = new Bitset();
                    if (useZeroOffset && ttype >= 0 && ttype < wordSize - 1)
                    {
                        current.shift = 0;
                    }
                    else
                    {
                        current.shift = ttype;
                    }

                    bitsetList.Add(current);
                }

                current.ttypes.Add(factory.GetTarget().GetTokenTypeAsTargetLabel(factory.GetGrammar(), ttype));
            }

            return bitsetList.ToArray();
        }
Example #2
0
    public Grid(Vector3 center, short rows, short cols, float spacing, bool empty) {
      Rows = rows;
      Cols = cols;
      Center = center;
      Spacing = spacing;
      Width = ((float)(Cols - 1)) * Spacing;
      Depth = ((float)(Rows - 1)) * Spacing;
      TotalNodes = Rows * Cols;
      HalfWidth = Width / 2f;
      HalfDepth = Depth / 2f;

      Left = center.x + -HalfWidth;
      Right = center.x + HalfWidth;
      Top = center.z + HalfDepth;
      Bottom = center.z + -HalfDepth;
      Connections = new Short2[8];

      if (!empty) {
        nodes = new Bitset(rows * cols);
      }
    }
Example #3
0
    public static Bitset operator>>(Bitset a, int k)
    {
        if (k < 0)
        {
            return(a << -k);
        }
        if ((k & 63) == 0)
        {
            return(a.Rshift(k >> 6));
        }
        if (k > 64)
        {
            return(a.Rshift(k >> 6) >> (k & 63));
        }
        var ret = new Bitset(a.size);

        for (int i = 0; i < ret.bits.Length; i++)
        {
            ret.bits[i] = a.bits[i] >> k | (i < ret.bits.Length - 1 ? a.bits[i + 1] << 64 - k : 0);
        }
        return(ret);
    }
Example #4
0
        public static void solve1()
        {
            Console.WriteLine("Print set type: 1 - Simple set, 2 - Multiset, 3 - Bitset");
            int ans = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Print max value");
            int maxVal = Convert.ToInt32(Console.ReadLine());
            Set s;

            if (ans == 1)
            {
                s = new SimpleSet(maxVal);
            }
            else if (ans == 2)
            {
                s = new Multiset(maxVal);
            }
            else
            {
                s = new Bitset(maxVal);
            }
            Console.WriteLine("Initialize set: 1 - From console, 2 - From file");
            ans = Convert.ToInt32(Console.ReadLine());
            try {
                if (ans == 1)
                {
                    Console.WriteLine("Print string");
                    string st = Console.ReadLine();
                    s.Build(st);
                }
                else
                {
                    Console.WriteLine("Print file");
                    string       name   = Console.ReadLine();
                    FileStream   file1  = new FileStream(name, FileMode.Open);
                    StreamReader reader = new StreamReader(file1);
                    var          ar     = new List <int>();
                    while (!reader.EndOfStream)
                    {
                        int tmp = Convert.ToInt32(reader.ReadLine());
                        ar.Add(tmp);
                    }
                    int[] a = new int[ar.Count];
                    for (int i = 0; i < ar.Count; i++)
                    {
                        a[i] = ar[i];
                    }
                    s.Build(a);
                }
            }
            catch (OutOfRangeException e) {
                Console.WriteLine("Out of range");
            }

            Console.WriteLine("Operations:\n1 - Add\n2 - Erase\n3 - Check\n4 - Print set\n5 - Exit");

            while (true)
            {
                Console.WriteLine("Print operation");
                int typ  = Convert.ToInt32(Console.ReadLine());
                int ansx = -1;
                if (typ <= 3)
                {
                    Console.WriteLine("Print number");
                    ansx = Convert.ToInt32(Console.ReadLine());
                }
                if (typ == 1)
                {
                    try {
                        s.AddEl(ansx);
                    }
                    catch (OutOfRangeException e) {
                        Console.WriteLine("Out of range");
                    }
                }
                else if (typ == 2)
                {
                    s.EraseEl(ansx);
                }
                else if (typ == 3)
                {
                    if (s.CheckEl(ansx))
                    {
                        Console.WriteLine("Yes");
                    }
                    else
                    {
                        Console.WriteLine("No");
                    }
                }
                else if (typ == 4)
                {
                    s.Print();
                }
                else if (typ == 5)
                {
                    break;
                }
            }
        }
Example #5
0
 public MessageSendedEventArgs(Bitset bitset)
 {
     this.bitset = bitset;
 }