Esempio n. 1
0
        public override T Compute <T>(T val)
        {
            lock (Table)
            {
                if (Table[_flag] == null)
                {
                    Table.Add(_flag, val);
                    CountTable.Add(_flag, 1);
                }
                else
                {
                    List <object> list = (List <object>)Table[_flag];
                    list.AddRange((List <object>)(object) val);

                    Table[_flag] = list;
                    int count = int.Parse(CountTable[_flag].ToString());
                    CountTable[_flag] = count + 1;
                }
            }
            if (Waite(_flag))
            {
                T t = (T)Convert.ChangeType(Table[_flag], typeof(T));
                return(t);
            }
            throw new TimeoutException();
        }
Esempio n. 2
0
        //public override T Compute<T>(T val)
        //{
        //    return default(T);
        //}

        public T[] ArrayCompute <T>(T[] val)
        {
            lock (Table)
            {
                if (Table[_flag] == null)
                {
                    Table.Add(_flag, ChangeType(val));
                    CountTable.Add(_flag, 1);
                }
                else
                {
                    double[]             list    = (double[])Table[_flag];
                    CombineSort <double> combine = new CombineSort <double>();
                    list         = combine.GetResult(list, ChangeType(val));
                    Table[_flag] = list;
                    int count = int.Parse(CountTable[_flag].ToString());
                    CountTable[_flag] = count + 1;
                }
            }
            if (Waite(_flag))
            {
                return(Array.ConvertAll((double[])Table[_flag],
                                        n => (T)Convert.ChangeType(n, typeof(T))));
            }
            throw new TimeoutException();
        }
Esempio n. 3
0
        public override T Compute <T>(T val)
        {
            lock (Table)
            {
                if (Table[_flag] == null)
                {
                    Table.Add(_flag, val);
                    CountTable.Add(_flag, 1);
                }
                else
                {
                    List <object> objects    = (List <object>)Table[_flag];
                    List <object> newObjects = (List <object>)Convert.ChangeType(val, typeof(List <object>));
                    objects.AddRange(newObjects);
                    List <object> distinctObjects = new List <object>(objects.Distinct());
                    Table[_flag] = distinctObjects;

                    int count = int.Parse(CountTable[_flag].ToString());
                    CountTable[_flag] = count + 1;
                }
            }
            if (Waite(_flag))
            {
                T t = (T)Convert.ChangeType(Table[_flag], typeof(T));
                return(t);
            }
            throw new TimeoutException();
        }
Esempio n. 4
0
        public override T Compute <T>(T val)
        {
            lock (Table)
            {
                if (Table[_flag] == null)
                {
                    Table.Add(_flag, val);
                    CountTable.Add(_flag, 1);
                }
                else
                {
                    Hashtable oldTable     = (Hashtable)Table[_flag];
                    Hashtable currentTable = (Hashtable)(object)val;
                    foreach (DictionaryEntry dictionaryEntry in currentTable)
                    {
                        if (oldTable.ContainsKey(dictionaryEntry.Key))
                        {
                            double oldValue = double.Parse(oldTable[dictionaryEntry.Key].ToString());
                            oldTable[dictionaryEntry.Key] = oldValue + double.Parse(dictionaryEntry.Value.ToString());
                        }
                        else
                        {
                            oldTable.Add(dictionaryEntry.Key, dictionaryEntry.Value);
                        }
                    }

                    Table[_flag] = oldTable;
                    int count = int.Parse(CountTable[_flag].ToString());
                    CountTable[_flag] = count + 1;
                }
            }
            if (Waite(_flag))
            {
                T t = (T)Convert.ChangeType(Table[_flag], typeof(T));
                return(t);
            }
            throw new TimeoutException();
        }
Esempio n. 5
0
 public override T Compute <T>(T val)
 {
     lock (Table)
     {
         if (Table[_flag] == null)
         {
             Table.Add(_flag, val);
             CountTable.Add(_flag, 1);
         }
         else
         {
             double average = (double.Parse(Table[_flag].ToString()) + double.Parse(val.ToString())) / 2.0;
             Table[_flag] = average;
             int count = int.Parse(CountTable[_flag].ToString());
             CountTable[_flag] = count + 1;
         }
     }
     if (Waite(_flag))
     {
         T t = (T)Convert.ChangeType(Table[_flag], typeof(T));
         return(t);
     }
     throw new TimeoutException();
 }