Esempio n. 1
0
        public IAsyncOperation <LoadMoreItemsResult> LoadMoreItemsAsync(uint phase)
        {
            return(AsyncInfo.Run(async token =>
            {
                if (phase == 0)
                {
                    var response = await _protoService.SendAsync(new SearchContacts(_query, 100));
                    if (response is TdWindows.Users users)
                    {
                        foreach (var id in users.UserIds)
                        {
                            var user = _protoService.GetUser(id);
                            if (user != null)
                            {
                                _users.Add(id);
                                _local.Add(new SearchResult(user, _query, false));
                            }
                        }
                    }
                }
                else if (phase == 1)
                {
                    var response = await _protoService.SendAsync(new SearchChatsOnServer(_query, 100));
                    if (response is TdWindows.Chats chats && _local != null)
                    {
                        foreach (var id in chats.ChatIds)
                        {
                            var chat = _protoService.GetChat(id);
                            if (chat != null && chat.Type is ChatTypePrivate privata)
                            {
                                if (_users.Contains(privata.UserId))
                                {
                                    continue;
                                }

                                _local.Add(new SearchResult(chat, _query, false));
                            }
                        }
                    }
                }
                else if (phase == 2)
                {
                    var response = await _protoService.SendAsync(new SearchPublicChats(_query));
                    if (response is TdWindows.Chats chats)
                    {
                        foreach (var id in chats.ChatIds)
                        {
                            var chat = _protoService.GetChat(id);
                            if (chat != null && chat.Type is ChatTypePrivate)
                            {
                                _remote.Add(new SearchResult(chat, _query, true));
                            }
                        }
                    }
                }

                return new LoadMoreItemsResult();
            }));
        }
Esempio n. 2
0
        protected RootClassDescriptor <T> AddClass <T>()
        {
            var classDescriptor = new RootClassDescriptor <T>();

            this.AddClass(classDescriptor);
            _classDescriptors.Add(classDescriptor);

            return(classDescriptor);
        }
Esempio n. 3
0
        public void Can_Do_Simple_Adds_Like_A_Regular_List()
        {
            var list = new KeyedList <Subject>();

            list.Add(new Subject("a"));
            list.Add(new Subject("b"));
            list.Add(new Subject("c"));
            list.Add(new Subject("d"));

            Assert.That(list.Count, Is.EqualTo(4));
        }
Esempio n. 4
0
        public void Can_Do_Simple_Adds_Like_A_Regular_List()
        {
            var list = new KeyedList<Subject>();

            list.Add(new Subject("a"));
            list.Add(new Subject("b"));
            list.Add(new Subject("c"));
            list.Add(new Subject("d"));

            Assert.That(list.Count, Is.EqualTo(4));
        }
        /// <summary>
        /// Creates and returns a keyboard definition object based on the ID.
        /// </summary>
        public IKeyboardDefinition CreateKeyboard(string id, KeyboardFormat format, IEnumerable <string> urls)
        {
            KeyboardDescription keyboard;

            if (!_keyboards.TryGet(id, out keyboard))
            {
                var firstCompatibleAdapter = _adaptors.Values.FirstOrDefault(adaptor => adaptor.CanHandleFormat(format));
                if (firstCompatibleAdapter == null)
                {
                    throw new ArgumentException(string.Format("Did not find {0} in {1} adapters", format, _adaptors.Count), "format");
                }
                keyboard = firstCompatibleAdapter.CreateKeyboardDefinition(id);
                _keyboards.Add(keyboard);
            }

            keyboard.Format = format;
            if (urls != null)
            {
                foreach (string url in urls)
                {
                    keyboard.Urls.Add(url);
                }
            }
            return(keyboard);
        }
Esempio n. 6
0
        public void Start()
        {
            Console.WriteLine("============Except Demo============");
            // initialize datas
            uint[] ids   = createIDs(10);
            string idstr = ids[0].ToString();

            for (int i = 1; i < ids.Length; i++)
            {
                idstr += " " + ids[i].ToString();
            }

            // add
            KeyedList <uint, DemoItem> list    = new KeyedList <uint, DemoItem>();
            KeyedList <uint, DemoItem> subList = new KeyedList <uint, DemoItem>();

            for (int i = 0; i < ids.Length; i++)
            {
                var item = new DemoItem(ids[i], $"Item_{ids[i]}");
                list.Add(item);
                if (i < ids.Length / 2)
                {
                    subList.Add(item);
                }
            }

            Console.WriteLine("Before Except:");
            print(list);
            Console.WriteLine("Sub List:");
            print(subList);
            Console.WriteLine("After Except");
            list = KeyedList <uint, DemoItem> .Except(list, subList);

            print(list);
        }
Esempio n. 7
0
        public void Start()
        {
            Console.WriteLine("==========Add/Remove Demo==========");
            // initialize datas
            uint[] ids   = createIDs(10);
            string idstr = ids[0].ToString();

            for (int i = 1; i < ids.Length; i++)
            {
                idstr += " " + ids[i].ToString();
            }
            Console.WriteLine("Before add : ");
            Console.WriteLine(idstr);

            // add demo
            KeyedList <uint, DemoItem> list = new KeyedList <uint, DemoItem>();

            for (int i = 0; i < ids.Length; i++)
            {
                var item = new DemoItem(ids[i], $"Item_{ids[i]}");
                list.Add(item);
            }
            Console.WriteLine("After add : ");
            print(list);

            // remove demo
            for (int i = 0; i < ids.Length / 2; i++)
            {
                list.RemoveByKey(ids[i]);
            }
            Console.WriteLine("After remove : ");
            print(list);
        }
Esempio n. 8
0
        public void Start()
        {
            Console.WriteLine("============Search Demo============");
            // initialize datas
            uint[] ids   = createIDs(10);
            string idstr = ids[0].ToString();

            for (int i = 1; i < ids.Length; i++)
            {
                idstr += " " + ids[i].ToString();
            }

            // add
            KeyedList <uint, DemoItem> list = new KeyedList <uint, DemoItem>();

            for (int i = 0; i < ids.Length; i++)
            {
                var item = new DemoItem(ids[i], $"Item_{ids[i]}");
                list.Add(item);
            }

            // search demo
            string itemStr = list.FindByKey(ids[0]).Data.ToString();

            for (int i = 1; i < ids.Length; i++)
            {
                itemStr += ", " + list.FindByKey(ids[i]).Data.ToString();
            }
            Console.WriteLine($"Search by ({idstr}) :");
            Console.WriteLine(itemStr);
        }
Esempio n. 9
0
        /// <summary>
        /// Creates and returns a keyboard definition object based on the ID.
        /// </summary>
        public IKeyboardDefinition CreateKeyboard(string id, KeyboardFormat format, IEnumerable <string> urls)
        {
            KeyboardDescription keyboard;

            if (!_keyboards.TryGet(id, out keyboard))
            {
                var firstCompatibleAdapter = _adaptors.Values.FirstOrDefault(adaptor => adaptor.CanHandleFormat(format));
                if (firstCompatibleAdapter == null)
                {
                    Debug.Fail($"Could not load keyboard for {id}. Did not find {format} in {_adaptors.Count} adapters");
                    return(new UnsupportedKeyboardDefinition(id));
                }
                keyboard = firstCompatibleAdapter.CreateKeyboardDefinition(id);
                _keyboards.Add(keyboard);
            }

            keyboard.Format = format;
            if (urls != null)
            {
                foreach (string url in urls)
                {
                    keyboard.Urls.Add(url);
                }
            }
            return(keyboard);
        }
Esempio n. 10
0
 public bool Accept(out Player player)
 {
     if (waitingQueue.Count <= 0)
     {
         player = null;
         return(false);
     }
     player = waitingQueue[0];
     playingList.Add(player);
     return(true);
 }
Esempio n. 11
0
        private void LoadMethods(ClassDiagramVisitorContext context)
        {
            var methods = this.ReflectedType.GetMethods(context.ShowMethodsBindingFlags).OrderBy(method => method.Name);

            foreach (var method in methods)
            {
                if (!method.IsProperty()) // weed up the compiler generated methods for properties
                {
                    _methods.Add(new ClassMethodDescriptor(method));
                }
            }
        }
Esempio n. 12
0
        private static IKeyedCollection <string, SldrLanguageTagInfo> DeriveTagsFromJsonEntries(List <AllTagEntry> rootObject)
        {
            var tags = new KeyedList <string, SldrLanguageTagInfo>(info => info.LanguageTag, StringComparer.InvariantCultureIgnoreCase);

            foreach (AllTagEntry entry in rootObject)
            {
                // tags starting with x- have undefined structure so ignoring them
                // tags starting with _ showed up in buggy data so we'll drop them also
                if (!entry.tag.StartsWith("x-") && !entry.tag.StartsWith("_"))
                {
                    LanguageSubtag languageTag;
                    if (!entry.deprecated && !StandardSubtags.RegisteredLanguages.TryGet(entry.tag.Split('-')[0], out languageTag))
                    {
                        if (entry.iso639_3 == null)
                        {
                            StandardSubtags.AddLanguage(entry.tag.Split('-')[0], entry.name, false, entry.tag.Split('-')[0]);
                        }
                        else if (!StandardSubtags.RegisteredLanguages.TryGet(entry.iso639_3, out languageTag))
                        {
                            StandardSubtags.AddLanguage(entry.iso639_3, entry.name, false, entry.iso639_3);
                        }
                    }
                    string implicitStringCode = null;

                    // the script is always in the full tag
                    string scriptCode = entry.full.Split('-')[1];
                    if (scriptCode.Length == 4)
                    {
                        var tagComponents = entry.tag.Split('-');

                        ScriptSubtag scriptTag;
                        if (!StandardSubtags.RegisteredScripts.TryGet(scriptCode, out scriptTag))
                        {
                            StandardSubtags.AddScript(scriptCode, scriptCode);
                        }

                        // if the script is also in the tag then it is explicit not implicit
                        if (tagComponents.Length == 1 || tagComponents[1] != scriptCode)
                        {
                            implicitStringCode = scriptCode;
                        }
                    }
                    tags.Add(new SldrLanguageTagInfo(entry.tag, implicitStringCode, entry.tag, entry.sldr));
                }
            }
            return(tags);
        }
        private Repository ToRepository(MRepository mRepository)
        {
            Timing t = new Timing();
            KeyedList <string, Branch>    rBranches = new KeyedList <string, Branch>(b => b.Id);
            Dictionary <CommitId, Commit> rCommits  = new Dictionary <CommitId, Commit>();
            Branch   currentBranch = null;
            Commit   currentCommit = null;
            CommitId rootCommitId  = mRepository.RootCommitId;

            Repository repository = new Repository(
                mRepository,
                new Lazy <IReadOnlyKeyedList <string, Branch> >(() => rBranches),
                new Lazy <IReadOnlyDictionary <CommitId, Commit> >(() => rCommits),
                new Lazy <Branch>(() => currentBranch),
                new Lazy <Commit>(() => currentCommit),
                commitsDetailsService,
                mRepository.Status,
                rootCommitId,
                mRepository.Uncommitted?.Id ?? CommitId.None);

            foreach (var mCommit in mRepository.Commits.Values)
            {
                Commit commit = Converter.ToCommit(repository, mCommit);
                rCommits[commit.Id] = commit;
                if (mCommit == mRepository.CurrentCommit)
                {
                    currentCommit = commit;
                }
            }

            foreach (var mBranch in mRepository.Branches)
            {
                Branch branch = Converter.ToBranch(repository, mBranch.Value);
                rBranches.Add(branch);

                if (mBranch.Value == mRepository.CurrentBranch)
                {
                    currentBranch = branch;
                }
            }

            t.Log($"Created repository {repository.Commits.Count} commits");
            return(repository);
        }
Esempio n. 14
0
        public bool Add(Node node)
        {
            Nodes.Add(node);

            var group = new Group(++groupID);

            group.Add(node);
            Groups.Add(group);
            node.Group = group;

            lookupByType.Add(node.Type, node);

            if (node.ID != null)
            {
                lookupByKey.Add(node.ID, node);
            }

            return(true);
        }
Esempio n. 15
0
        public void Duplicates_Are_Treated_As_Last_One_Wins()
        {
            var list = new KeyedList<Subject>();

            list.Add(new Subject("a"));
            list.Add(new Subject("b"));
            list.Add(new Subject("b"));
            var b = new Subject("b");
            list.Add(b);
            list.Add(new Subject("c"));
            list.Add(new Subject("d"));

            Assert.That(list.Count, Is.EqualTo(4));
            Assert.That(list["b"], Is.EqualTo(b));
        }
Esempio n. 16
0
        public void Duplicates_Are_Treated_As_Last_One_Wins()
        {
            var list = new KeyedList <Subject>();

            list.Add(new Subject("a"));
            list.Add(new Subject("b"));
            list.Add(new Subject("b"));
            var b = new Subject("b");

            list.Add(b);
            list.Add(new Subject("c"));
            list.Add(new Subject("d"));

            Assert.That(list.Count, Is.EqualTo(4));
            Assert.That(list["b"], Is.EqualTo(b));
        }
Esempio n. 17
0
        public void Start()
        {
            Console.WriteLine("=============Union Demo============");
            // initialize datas
            uint[] ids   = createIDs(10);
            string idstr = ids[0].ToString();

            for (int i = 1; i < ids.Length; i++)
            {
                idstr += " " + ids[i].ToString();
            }

            // add
            KeyedList <uint, DemoItem> list  = new KeyedList <uint, DemoItem>();
            KeyedList <uint, DemoItem> list1 = new KeyedList <uint, DemoItem>();
            KeyedList <uint, DemoItem> list2 = new KeyedList <uint, DemoItem>();

            for (int i = 0; i < ids.Length; i++)
            {
                var item = new DemoItem(ids[i], $"Item_{ids[i]}");
                if (i < ids.Length / 2)
                {
                    list1.Add(item);
                }
                else
                {
                    list2.Add(item);
                }
            }

            Console.WriteLine("List1:");
            print(list1);
            Console.WriteLine("List2:");
            print(list2);
            Console.WriteLine("After Union");
            list = KeyedList <uint, DemoItem> .Union(list1, list2);

            print(list);
        }
Esempio n. 18
0
        private async Task <KeyedList <string, TLObject> > SearchGlobalAsync(string query)
        {
            if (query.Length < 5)
            {
                return(null);
            }

            var result = await ProtoService.SearchAsync(query, 100);

            if (result.IsSucceeded)
            {
                if (result.Result.Results.Count > 0)
                {
                    var parent = new KeyedList <string, TLObject>("Global search results");

                    CacheService.SyncUsersAndChats(result.Result.Users, result.Result.Chats,
                                                   tuple =>
                    {
                        result.Result.Users = tuple.Item1;
                        result.Result.Chats = tuple.Item2;

                        foreach (var peer in result.Result.Results)
                        {
                            var item = result.Result.Users.FirstOrDefault(x => x.Id == peer.Id);
                            if (item != null)
                            {
                                parent.Add(item);
                            }
                        }
                    });

                    return(parent);
                }
            }

            return(null);
        }
Esempio n. 19
0
 public void Add(SourceInfo source)
 {
     SourceInfos.Add(source);
     SourceLookup.Add(source.MethodID, source);
 }
Esempio n. 20
0
		internal static IKeyedCollection<string, SldrLanguageTagInfo> ParseAllTags(string allTagsContent)
		{
			string[] allTags = allTagsContent.Replace("\r\n", "\n").Split(new[] {"\n"}, StringSplitOptions.RemoveEmptyEntries);
			var tags = new KeyedList<string, SldrLanguageTagInfo>(info => info.LanguageTag, StringComparer.InvariantCultureIgnoreCase);
			foreach (string line in allTags)
			{
				string tagsStr = line;
				// trim off the explicit inheritance relationship information, we don't care about inheritance
				int index = line.LastIndexOf('>');
				if (index != -1)
					tagsStr = line.Substring(0, index).Trim();
				// split the the line into groups of equivalent language tags
				// the bar character is used to show implicit inheritance relationships between tags,
				// we don't care about inheritance
				string[] equivalentTagsStrs = tagsStr.Split('|');
				foreach (string equivalentTagsStr in equivalentTagsStrs)
				{
					// split each group of equivalent language tags into individual language tags
					string[] tagStrs = equivalentTagsStr.Split('=');
					for (int i = 0; i < tagStrs.Length; i++)
						tagStrs[i] = tagStrs[i].Trim();
					// check if language tag is available in the SLDR
					bool isAvailable = tagStrs[0].StartsWith("*");
					if (isAvailable)
						tagStrs[0] = tagStrs[0].Substring(1);
					string sldrLangTag = tagStrs[0];
					// check if a tag with a script code is equivalent to a tag without a script code
					// this tells us that the script is implicit
					string langTag, implicitStringCode;
					if (equivalentTagsStrs.Length == 1 && tagStrs.Length == 1)
					{
						// special case where there is a single tag on a line
						// if it contains a script code, then the script is implicit
						string[] components = tagStrs[0].Split('-');
						if (components.Length == 2 && components[1].Length == 4)
						{
							langTag = components[0];
							implicitStringCode = components[1];
						}
						else
						{
							langTag = tagStrs[0];
							implicitStringCode = null;
						}
					}
					else
					{
						var minTag = tagStrs.Select(t => new {Tag = t, Components = t.Split('-')}).MinBy(t => t.Components.Length);
						langTag = minTag.Tag;
						implicitStringCode = null;
						// only look for an implicit script code if the minimal tag has no script code
						if (minTag.Components.Length < 2 || minTag.Components[1].Length != 4)
						{
							foreach (string tagStr in tagStrs)
							{
								string[] components = tagStr.Split('-');
								if (components.Length == minTag.Components.Length + 1 && components[1].Length == 4)
									implicitStringCode = components[1];
							}
						}
					}
					SldrLanguageTagInfo existingTag;
					if (tags.TryGet(langTag, out existingTag))
					{
						// alltags.txt can contain multiple lines that contain the same language tag.
						// if one of the lines contains information on an implicit script for a language tag, 
						// we don't want to lose that information, so we preserve it by not replacing the
						// SldrLanguageTagInfo object for this language tag.
						if (existingTag.ImplicitScriptCode != null)
							continue;
						tags.Remove(langTag);
					}
					tags.Add(new SldrLanguageTagInfo(langTag, implicitStringCode, sldrLangTag, isAvailable));
				}
			}

			return tags;
		}
Esempio n. 21
0
 public void Add(SourceLabelInfo sourceLabel)
 {
     SourceLabels.Add(sourceLabel);
     SourceLabelLookup.Add(sourceLabel.MethodID, sourceLabel);
 }
Esempio n. 22
0
        internal static IKeyedCollection <string, SldrLanguageTagInfo> ParseAllTagsJson(string allTagsContent)
        {
            // read in the json file

            /*		{
             *                      "full": "aa-Latn-ET",
             *                      "name": "Afar",
             *                      "names": [
             *                              "Adal",
             *                              ...
             *                      ],
             *                      "sldr": true,
             *                      "tag": "aa",
             *                      "tags": [
             *                              "aa-ET",
             *                              "aa-Latn"
             *                      ]
             *              },*/
            // for each entry
            // tag -> langtag which is same as sldrtag
            // sldr -> isAvailable
            // tags -> process to find implicitScript

            var tags = new KeyedList <string, SldrLanguageTagInfo>(info => info.LanguageTag, StringComparer.InvariantCultureIgnoreCase);

            List <AllTagEntry> rootObject = JsonConvert.DeserializeObject <List <AllTagEntry> >(allTagsContent);

            foreach (AllTagEntry entry in rootObject)
            {
                if (!entry.tag.StartsWith("x-"))                 // tags starting with x- have undefined structure so ignoring them
                {
                    LanguageSubtag languageTag;
                    if (!entry.deprecated && !StandardSubtags.RegisteredLanguages.TryGet(entry.tag.Split('-')[0], out languageTag))
                    {
                        if (entry.iso639_3 == null)
                        {
                            StandardSubtags.AddLanguage(entry.tag.Split('-')[0], entry.name, false, entry.tag.Split('-')[0]);
                        }
                        else if (!StandardSubtags.RegisteredLanguages.TryGet(entry.iso639_3, out languageTag))
                        {
                            StandardSubtags.AddLanguage(entry.iso639_3, entry.name, false, entry.iso639_3);
                        }
                    }
                    string implicitStringCode = null;

                    // the script is always in the full tag
                    string scriptCode = entry.full.Split('-')[1];
                    if (scriptCode.Length == 4)
                    {
                        var tagComponents = entry.tag.Split('-');

                        ScriptSubtag scriptTag;
                        if (!StandardSubtags.RegisteredScripts.TryGet(scriptCode, out scriptTag))
                        {
                            StandardSubtags.AddScript(scriptCode, scriptCode);
                        }

                        // if the script is also in the tag then it is explicit not implicit
                        if (tagComponents.Length == 1 || tagComponents[1] != scriptCode)
                        {
                            implicitStringCode = scriptCode;
                        }
                    }
                    tags.Add(new SldrLanguageTagInfo(entry.tag, implicitStringCode, entry.tag, entry.sldr));
                }
            }
            return(tags);
        }
Esempio n. 23
0
        static void SortTest1(string[] args)
        {
            CreateRandomFile(@"..\..\dic.txt");
            string[]      aArray = File.ReadAllLines(@"Rndm-dic.txt", Encoding.Default);
            string[]      bArray = File.ReadAllLines(@"Rndm-dic.txt", Encoding.Default);
            List <string> aList  = new List <string>(aArray);
            List <string> sList  = new List <string>(aArray);
            List <string> sList2 = new List <string>(aArray);

            SortTests.Sorting.sfList sList3 = new sfList(aArray);

            KeyedList <string, int> kList     = new KeyedList <string, int>(aArray.Length);
            KeyedList <string, int> kListDesc = new KeyedList <string, int>(aArray.Length);
            int val = 1;

            foreach (string s in sList)
            {
                kList.Add(s, val); //val contains original line position of string
                kListDesc.Add(s, val);
                ++val;
            }
            sList.Clear();

            TimeCounter StopWatch = new TimeCounter();

            StopWatch.SetOneProcessorAffinity();
            Console.WriteLine("base Cycles = {0} IsHighRes = {1}", TimeCounter.Frequency, TimeCounter.IsHighResolution);
            StopWatch.Start();
            //List<string> cList = StringSort.Sort(aList);
            List <string> cList = new List <string>(aList);

            StopWatch.Stop();
            Console.WriteLine("MS to sort copy: {0}", StopWatch.ElapsedMilSec);
            int n = 0;

            foreach (string s in cList)
            {
                Console.WriteLine(s);
                if (++n > 1)
                {
                    break;
                }
            }

            aList.Clear();

            StopWatch.StartNew();
            Array.Sort <string>(bArray, CompareString);
            StopWatch.Stop();
            Console.WriteLine("MS to Array.Sort<string> bArray: {0}", StopWatch.ElapsedMilSec);
            for (int i = 0; i < bArray.Length; ++i)
            {
                Console.WriteLine(bArray[i]);
                if (i == 1)
                {
                    break;
                }
            }
            //reset bArray to unsorted
            aArray.CopyTo(bArray, 0);

            StopWatch.StartNew();
            StringSort.Sort(aArray);
            StopWatch.Stop();
            Console.WriteLine("MS to sort aArray: {0}", StopWatch.ElapsedMilSec);
            for (int i = 0; i < aArray.Length; ++i)
            {
                Console.WriteLine(aArray[i]);
                if (i == 1)
                {
                    break;
                }
            }

            StopWatch.StartNew();
            Sedgewick.Sort(ref bArray);
            StopWatch.Stop();
            Console.WriteLine("MS to Sedgewick Sort bArray: {0}", StopWatch.ElapsedMilSec);
            for (int i = 0; i < bArray.Length; ++i)
            {
                Console.WriteLine(bArray[i]);
                if (i == 1)
                {
                    break;
                }
            }

            StopWatch.StartNew();
            sList2.Sort(CompareString); //sort using List<string> method
                                        //sList2.Sort(CompareString);
            StopWatch.Stop();
            Console.WriteLine("MS to List.Sort() sList2: {0}", StopWatch.ElapsedMilSec);
            for (int i = 0; i < sList2.Count; ++i)
            {
                Console.WriteLine(sList2[i]);
                if (i == 1)
                {
                    break;
                }
            }
            sList2.Clear();

            StopWatch.StartNew();
            sList3.Sort(); //sort using StringSort replacement
            StopWatch.Stop();
            Console.WriteLine("MS to sfList.Sort() sList3: {0}", StopWatch.ElapsedMilSec);
            for (int i = 0; i < sList3.Count; ++i)
            {
                Console.WriteLine(sList3[i]);
                if (i == 1)
                {
                    break;
                }
            }

            StopWatch.StartNew();
            kList.Sort();
            StopWatch.Stop();
            Console.WriteLine("MS to KeyedList.Sort() kList: {0}", StopWatch.ElapsedMilSec);
            for (int i = 0; i < kList.Count; ++i)
            {
                Console.WriteLine(kList[i]);
                if (i == 1)
                {
                    break;
                }
            }
            //test the sort
            bool sorted = IsSortedTest(kList, kList.SortAscd);

            Console.WriteLine("Test: kList is sorted = {0}", sorted);

            kListDesc.SortAscd = false; //try sorting in descending order
            StopWatch.StartNew();
            kListDesc.Sort();
            StopWatch.Stop();
            Console.WriteLine("MS to KeyedList.Sort() kListDesc: {0}", StopWatch.ElapsedMilSec);
            for (int i = 0; i < kListDesc.Count; ++i)
            {
                Console.WriteLine(kListDesc[i]);
                if (i == 1)
                {
                    break;
                }
            }
            //test the sort
            sorted = IsSortedTest(kListDesc, kListDesc.SortAscd);
            Console.WriteLine("Test: kListDesc is sorted descending = {0}", sorted);

            string[] wArray = File.ReadAllLines(@"Rndm-dic.txt", Encoding.Default);

            //this is slower than stringSort
            //WQSort wqs = new WQSort();
            //StopWatch.StartNew();
            //wqs.Sort(wArray);
            //StopWatch.Stop();
            //Console.WriteLine("MS to WQSort.Sort() wArray: {0}", StopWatch.ElapsedMilSec);
            //for (int i = 0; i < wArray.Length; ++i)
            //{
            //  Console.WriteLine(wArray[i]);
            //  if (i == 1) break;
            //}
            List <int> lstInt = new List <int>(wArray.Length);
            Random     rand   = new Random((int)StopWatch.ElapsedMilSec);

            for (int i = 0; i < wArray.Length; ++i)
            {
                lstInt.Add(rand.Next());
            }
            StopWatch.StartNew();
            lstInt.Sort();
            StopWatch.Stop();
            Console.WriteLine("MS to List<int>.Sort() with {0} elements: {1:f1}", wArray.Length, StopWatch.ElapsedMilSec);
            Console.WriteLine("First, Second, Last integer in sorted List");
            Console.WriteLine(lstInt[0]);
            Console.WriteLine(lstInt[1]);
            Console.WriteLine(lstInt[wArray.Length - 1]);
            StopWatch.RestoreProcessorAffinity(); //set this thread back to default Proccessor Affinity
        }
Esempio n. 24
0
 public void Add(SymbolInfo symbol)
 {
     Symbols.Add(symbol);
     SymbolLookup.Add(symbol.Address, symbol);
 }
Esempio n. 25
0
 protected ClassDiagram AddAssembly(Assembly assembly)
 {
     _assemblyDescriptors.Add(new AssemblyDescriptor(assembly));
     return(this);
 }
Esempio n. 26
0
        internal static IKeyedCollection <string, SldrLanguageTagInfo> ParseAllTags(string allTagsContent)
        {
            string[] allTags = allTagsContent.Replace("\r\n", "\n").Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
            var      tags    = new KeyedList <string, SldrLanguageTagInfo>(info => info.LanguageTag, StringComparer.InvariantCultureIgnoreCase);

            foreach (string line in allTags)
            {
                string tagsStr = line;
                // trim off the explicit inheritance relationship information, we don't care about inheritance
                int index = line.LastIndexOf('>');
                if (index != -1)
                {
                    tagsStr = line.Substring(0, index).Trim();
                }
                // split the the line into groups of equivalent language tags
                // the bar character is used to show implicit inheritance relationships between tags,
                // we don't care about inheritance
                string[] equivalentTagsStrs = tagsStr.Split('|');
                foreach (string equivalentTagsStr in equivalentTagsStrs)
                {
                    // split each group of equivalent language tags into individual language tags
                    string[] tagStrs = equivalentTagsStr.Split('=');
                    for (int i = 0; i < tagStrs.Length; i++)
                    {
                        tagStrs[i] = tagStrs[i].Trim();
                    }
                    // check if language tag is available in the SLDR
                    bool isAvailable = tagStrs[0].StartsWith("*");
                    if (isAvailable)
                    {
                        tagStrs[0] = tagStrs[0].Substring(1);
                    }
                    string sldrLangTag = tagStrs[0];
                    // check if a tag with a script code is equivalent to a tag without a script code
                    // this tells us that the script is implicit
                    string langTag, implicitStringCode;
                    if (equivalentTagsStrs.Length == 1 && tagStrs.Length == 1)
                    {
                        // special case where there is a single tag on a line
                        // if it contains a script code, then the script is implicit
                        string[] components = tagStrs[0].Split('-');
                        if (components.Length == 2 && components[1].Length == 4)
                        {
                            langTag            = components[0];
                            implicitStringCode = components[1];
                        }
                        else
                        {
                            langTag            = tagStrs[0];
                            implicitStringCode = null;
                        }
                    }
                    else
                    {
                        var minTag = tagStrs.Select(t => new { Tag = t, Components = t.Split('-') }).MinBy(t => t.Components.Length);
                        langTag            = minTag.Tag;
                        implicitStringCode = null;
                        // only look for an implicit script code if the minimal tag has no script code
                        if (minTag.Components.Length < 2 || minTag.Components[1].Length != 4)
                        {
                            foreach (string tagStr in tagStrs)
                            {
                                string[] components = tagStr.Split('-');
                                if (components.Length == minTag.Components.Length + 1 && components[1].Length == 4)
                                {
                                    implicitStringCode = components[1];
                                }
                            }
                        }
                    }
                    SldrLanguageTagInfo existingTag;
                    if (tags.TryGet(langTag, out existingTag))
                    {
                        // alltags.txt can contain multiple lines that contain the same language tag.
                        // if one of the lines contains information on an implicit script for a language tag,
                        // we don't want to lose that information, so we preserve it by not replacing the
                        // SldrLanguageTagInfo object for this language tag.
                        if (existingTag.ImplicitScriptCode != null)
                        {
                            continue;
                        }
                        tags.Remove(langTag);
                    }
                    tags.Add(new SldrLanguageTagInfo(langTag, implicitStringCode, sldrLangTag, isAvailable));
                }
            }

            return(tags);
        }
Esempio n. 27
0
 protected override void OnRootClassVisited(ClassDescriptor rootClass)
 {
     _classes.Add(rootClass);
 }
Esempio n. 28
0
        private void UpdateBlockProtectInstructions()
        {
            foreach (var block in BasicBlocks)
            {
                var context = new Context(block.Last);

                while (context.IsEmpty || context.IsBlockEndInstruction || context.Instruction == IRInstruction.Flow)
                {
                    context.GotoPrevious();
                }

                if (context.Instruction is EndFinallyInstruction)
                {
                    context.SetInstruction(IRInstruction.FinallyEnd);

                    var entry = FindFinallyHandler(context.Node);
                    var list  = returns.Get(entry);

                    if (list == null)
                    {
                        return;
                    }

                    context.AppendInstruction(IRInstruction.FinallyReturn);

                    foreach (var returnBlock in list)
                    {
                        context.AddBranchTarget(returnBlock);
                    }
                }
                else if (context.Instruction is LeaveInstruction)
                {
                    // Find enclosing finally clause
                    bool createLink = false;

                    var entry = FindImmediateExceptionHandler(context.Node);

                    if (entry != null)
                    {
                        if (entry.IsLabelWithinTry(context.Label))
                        {
                            createLink = true;
                        }
                    }

                    if (createLink)
                    {
                        var tryFinallyBlock = context.BranchTargets[0];

                        returns.Add(entry, tryFinallyBlock);

                        context.SetInstruction(IRInstruction.TryEnd);

                        if (entry.HandlerType == ExceptionHandlerType.Finally)
                        {
                            var finallyBlock = BasicBlocks.GetByLabel(entry.HandlerStart);

                            context.AppendInstruction(IRInstruction.CallFinally, finallyBlock, tryFinallyBlock);
                        }
                        else
                        {
                            context.AppendInstruction(IRInstruction.Jmp, tryFinallyBlock);
                        }

                        //Debug.Assert(context.BasicBlock.NextBlocks.Count <= 1);
                    }
                    else
                    {
                        context.ReplaceInstructionOnly(IRInstruction.ExceptionEnd);
                    }
                }
            }
        }
Esempio n. 29
0
 public void CallingAddUpdatesIndex()
 {
     _keyedList.Add(12);
     Assert.IsTrue(_keyedList.ContainsKey(144));
 }