public void RemoveHashSet(IHashSet hashSet)
        {
            if (hashSet == null)
            {
                throw new ArgumentNullException(nameof(hashSet));
            }

            if (!_hashSets.Contains(hashSet))
            {
                throw new InvalidOperationException($"The {nameof(HashSets)} doesn't contain {nameof(hashSet)}");
            }

            try {
                var xDoc = XDocument.Load(GetDataFileName());
                var elem = xDoc.Root.Elements(Constants.XmlElemName_HashSets_Set).
                           FirstOrDefault(p => p.Attribute(Constants.XmlAttrName_HashSets_Set_GUID)?.Value == hashSet.GUID);

                if (elem != null)
                {
                    elem.Remove();
                }
                else
                {
                    LoggerService.WriteCallerLine($"{nameof(elem)} can't be null.");
                }

                _hashSets.Remove(hashSet);
                xDoc.Save(GetDataFileName());
            }
            catch (Exception ex) {
                LoggerService.WriteException(ex);
                throw;
            }
        }
Exemplo n.º 2
0
        public void Add_TwoEqualEntities_SizeEqualsOn(IHashSet <int> hasSet)
        {
            hasSet.Add(1);

            Assert.That(hasSet.Add(1), Is.EqualTo(false));
            Assert.That(hasSet.Count, Is.EqualTo(1));
        }
        public void AddHashSet(IHashSet hashSet)
        {
            if (hashSet == null)
            {
                throw new ArgumentNullException(nameof(hashSet));
            }

            try {
                var xDoc = XDocument.Load(GetDataFileName());
                var root = xDoc.Root;

                var hashSetElem = new XElement(Constants.XmlElemName_HashSets_Set);
                //必要元素;
                hashSetElem.SetAttributeValue(Constants.XmlAttrName_HashSets_Set_GUID, hashSet.GUID);
                hashSetElem.SetAttributeValue(Constants.XmlAttrName_HashSets_Set_StoragePath, hashSet.StoragePath);
                hashSetElem.SetAttributeValue(Constants.XmlAttrName_HashSets_Set_HashTypeGUID, hashSet.Hasher.GUID);

                //可选元素;
                hashSetElem.SetAttributeValue(Constants.XmlAttrName_HashSets_Set_Name, hashSet.Name);
                hashSetElem.SetXElemValue(hashSet.Description, Constants.XmlElemName_HashSets_Set_Description);
                hashSetElem.SetAttributeValue(Constants.XmlAttrName_HashSets_Set_IsEnabled, hashSet.IsEnabled.ToString());

                root.Add(hashSetElem);
                xDoc.Save(GetDataFileName());
                _hashSets.Add(hashSet);
            }
            catch (Exception ex) {
                LoggerService.WriteException(ex);
                throw;
            }
        }
Exemplo n.º 4
0
 private static void PrintSet <T>(IHashSet <T> set)
 {
     foreach (var element in set)
     {
         Console.Write("{0} ", element);
     }
     Console.WriteLine();
 }
Exemplo n.º 5
0
        public HashSetModel(IHashSet hashSet)
        {
            this.HashSet = hashSet ?? throw new ArgumentNullException(nameof(hashSet));

            this.HashSetName        = HashSet.Name;
            this.HashSetEnabled     = hashSet.IsEnabled;
            this.HashSetDescription = hashSet.Description;
        }
Exemplo n.º 6
0
        public void Containts_AddedFourItems_ForLastContaintsIsTrue(IHashSet <int> hasSet)
        {
            hasSet.Add(1);
            hasSet.Add(2);
            hasSet.Add(3);
            hasSet.Add(5);

            Assert.That(hasSet.Contains(3), Is.EqualTo(true));
            Assert.That(hasSet.Contains(4), Is.EqualTo(false));
        }
Exemplo n.º 7
0
        public void ListHashSetPairs(IHashSet hashSet)
        {
            if (hashSet == null)
            {
                throw new ArgumentNullException(nameof(hashSet));
            }

            IHashPair[] hashPairArray = null;
            //由于加载的哈希集可能较大,使用等待对话框;
            var loadingDialog = DialogService.Current.CreateLoadingDialog();

            loadingDialog.IsProgressVisible = false;
            loadingDialog.WindowTitle       = LanguageService.FindResourceString(Constants.WindowTitle_LoadingHashPairs);
            loadingDialog.DoWork           += delegate {
                try {
                    hashSet.BeginOpen();
                    hashPairArray = hashSet.GetAllHashPairs().ToArray();
                }
                catch (Exception ex) {
                    LoggerService.WriteException(ex);
                }
                finally {
                    hashSet.EndOpen();
                }
            };
            loadingDialog.RunWorkerCompleted += delegate {
                if (hashPairArray == null)
                {
                    return;
                }

                var window = new ListHashValuesDialog();
                var vm     = new ListHashValuesDialogViewModel(hashPairArray);
                window.DataContext = vm;
                if (ShellService.Current.Shell is Window shell && shell.IsLoaded)
                {
                    window.ShowInTaskbar = false;
                    window.Owner         = shell;
                }

                window.ShowDialog();
                window.DataContext = null;



#if DEBUG
                for (int i = 0; i < 2; i++)
                {
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
#endif
            };
            loadingDialog.ShowDialog();
        }
Exemplo n.º 8
0
 public LotteryService(
     IExtendedCacheClient cache, 
     ISchedulerService scheduler, 
     ITransactionService transactions, 
     LotteryEventHandler eventHandler)
 {
     this.transactions = transactions;
     this.scheduler = scheduler.CreateWorker(
         lotterySchedulerKey, eventHandler.HandleLotteryAsync);
     this.entrySet = cache.CreateHashSet<LotteryEntry>(eventHandler.LotteryObjectsKey);
 }
        /// <summary>
        /// 检查某个哈希集中是否包含某个哈希值;在调用本方法前,须先调用<see cref="IHashSet.BeginEdit"/>,并在完成并且必要时调用<see cref="IHashSet.EndEdit"/>
        /// </summary>
        /// <param name="hashSet"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool ContainsValue(this IHashSet hashSet, string value)
        {
            if (hashSet == null)
            {
                throw new ArgumentNullException(nameof(hashSet));
            }

            var pairs = hashSet.FindHashPairs(value);

            return(pairs.FirstOrDefault() != null);
        }
        /// <summary>
        /// 哈希集描述变化时,更新XML文件中的内容;
        /// </summary>
        /// <param name="hashSet"></param>
        private void OnHashSetDescriptionChanged(IHashSet hashSet)
        {
            if (hashSet == null)
            {
                return;
            }

            if (!_hashSets.Contains(hashSet))
            {
                return;
            }

            SetSetElemXElemValue(hashSet, Constants.XmlElemName_HashSets_Set_Description, hashSet.Description);
        }
        /// <summary>
        /// 哈希集名称变化时,更新XML文件中的内容;
        /// </summary>
        /// <param name="hashSet"></param>
        private void OnHashSetNameChanged(IHashSet hashSet)
        {
            if (hashSet == null)
            {
                return;
            }

            if (!_hashSets.Contains(hashSet))
            {
                return;
            }

            SetSetElemAttrValue(hashSet, Constants.XmlAttrName_HashSets_Set_Name, hashSet.Name);
        }
        /// <summary>
        /// 哈希集可用状态变化时,更新XML文件中的内容;
        /// </summary>
        /// <param name="hashSet"></param>
        private void OnHashSetIsEnabledChanged(IHashSet hashSet)
        {
            if (hashSet == null)
            {
                return;
            }

            if (!_hashSets.Contains(hashSet))
            {
                return;
            }

            SetSetElemAttrValue(hashSet, Constants.XmlAttrName_HashSets_Set_IsEnabled, hashSet.IsEnabled.ToString());
        }
Exemplo n.º 13
0
 //init with an expected size (the larger the size lesser the collission, but memory matters!)
 public HashSet(HashSetType type = HashSetType.SeparateChaining, int initialBucketSize = 2)
 {
     if (initialBucketSize < 2)
     {
         throw new Exception("Bucket Size must be greater than 2.");
     }
     if (type == HashSetType.SeparateChaining)
     {
         hashSet = new SeparateChainingHashSet <TV>(initialBucketSize);
     }
     else
     {
         hashSet = new OpenAddressHashSet <TV>(initialBucketSize);
     }
 }
        /// <summary>
        /// 设定哈希集节点的子节点值;
        /// </summary>
        /// <param name="xElemName"></param>
        /// <param name=""></param>
        private static void SetSetElemXElemValue(IHashSet hashSet, string xElemName, string value)
        {
            if (hashSet == null)
            {
                throw new ArgumentNullException(nameof(hashSet));
            }

            try {
                var xDoc    = XDocument.Load(GetDataFileName());
                var setElem = xDoc.Root.Elements(Constants.XmlElemName_HashSets_Set).
                              FirstOrDefault(p => p.Attribute(Constants.XmlAttrName_HashSets_Set_GUID)?.Value == hashSet.GUID);
                if (setElem == null)
                {
                    LoggerService.WriteCallerLine($"{nameof(setElem)} can't be null.");
                }
                setElem.SetXElemValue(value, xElemName);
                xDoc.Save(GetDataFileName());
            }
            catch (Exception ex) {
                LoggerService.WriteException(ex);
            }
        }
Exemplo n.º 15
0
 protected override void Put(IHashSet <string> collection, string value)
 {
     collection.Add(value);
     _last = value;
 }
Exemplo n.º 16
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="EnumerableChecker{T}" /> class.
 /// </summary>
 /// <param name="hashSet">The hash set.</param>
 /// <param name="generator">The generator.</param>
 public ConcurrentHashSetChecker(IHashSet <T> hashSet, Func <T> generator) : base(hashSet)
 {
     _generator = generator;
 }
 public static void ListHashSetPairs(IHashSet hashSet) => Current?.ListHashSetPairs(hashSet);
Exemplo n.º 18
0
 public void Init()
 {
     _set = new HashSet();
 }
Exemplo n.º 19
0
 protected override void RemoveLastPutValue(IHashSet <string> collection)
 {
     collection.Remove(_last);
 }
Exemplo n.º 20
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="EnumerableChecker{T}" /> class.
 /// </summary>
 /// <param name="hashSet">The hash set.</param>
 protected HashSetChecker(IHashSet <T> hashSet) : base(hashSet)
 {
     _hashSet = hashSet;
 }
 public static void RemoveHashSet(IHashSet hashSet) => Current?.RemoveHashSet(hashSet);
 public static void AddHashSet(IHashSet hashSet) => Current?.AddHashSet(hashSet);
Exemplo n.º 23
0
 protected override void PutMany(IHashSet <string> collection, params string[] values)
 {
     collection.AddMany(values);
     _last = values.LastOrDefault();
 }
Exemplo n.º 24
0
 /// <summary>Initializes a new instance of the <see cref="T:System.Object" /> class.</summary>
 public MarkedNode(GraphNode <T> node, IHashSet <GraphNode <T> > markingSet)
 {
     Node       = node;
     MarkingSet = markingSet;
 }