当前位置: 首页>>代码示例>>C#>>正文


C# SortedDictionary.Put方法代码示例

本文整理汇总了C#中SortedDictionary.Put方法的典型用法代码示例。如果您正苦于以下问题:C# SortedDictionary.Put方法的具体用法?C# SortedDictionary.Put怎么用?C# SortedDictionary.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SortedDictionary的用法示例。


在下文中一共展示了SortedDictionary.Put方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RemoteCheckpointDocID

        // Pusher overrides this to implement the .createTarget option
        /// <summary>This is the _local document ID stored on the remote server to keep track of state.
        ///     </summary>
        /// <remarks>
        /// This is the _local document ID stored on the remote server to keep track of state.
        /// Its ID is based on the local database ID (the private one, to make the result unguessable)
        /// and the remote database's URL.
        /// </remarks>
        internal string RemoteCheckpointDocID()
        {
            if (_remoteCheckpointDocID != null) {
                return _remoteCheckpointDocID;
            } else {
                // TODO: Needs to be consistent with -hasSameSettingsAs: --
                // TODO: If a.remoteCheckpointID == b.remoteCheckpointID then [a hasSameSettingsAs: b]

                if (LocalDatabase == null) {
                    return null;
                }

                // canonicalization: make sure it produces the same checkpoint id regardless of
                // ordering of filterparams / docids
                IDictionary<String, Object> filterParamsCanonical = null;
                if (FilterParams != null) {
                    filterParamsCanonical = new SortedDictionary<String, Object>(FilterParams);
                }

                List<String> docIdsSorted = null;
                if (DocIds != null) {
                    docIdsSorted = new List<String>(DocIds);
                    docIdsSorted.Sort();
                }

                // use a treemap rather than a dictionary for purposes of canonicalization
                var spec = new SortedDictionary<String, Object>();
                spec.Put("localUUID", LocalDatabase.PrivateUUID());
                spec.Put("remoteURL", RemoteUrl.AbsoluteUri);
                spec.Put("push", !IsPull);
                spec.Put("continuous", Continuous);

                if (Filter != null) {
                    spec.Put("filter", Filter);
                }
                if (filterParamsCanonical != null) {
                    spec.Put("filterParams", filterParamsCanonical);
                }
                if (docIdsSorted != null) {
                    spec.Put("docids", docIdsSorted);
                }

                IEnumerable<byte> inputBytes = null;
                try {
                    inputBytes = Manager.GetObjectMapper().WriteValueAsBytes(spec);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }

                _remoteCheckpointDocID = Misc.HexSHA1Digest(inputBytes);
                return _remoteCheckpointDocID;
            }
        }
开发者ID:woxihuanjia,项目名称:couchbase-lite-net,代码行数:61,代码来源:Replication.cs

示例2: List

			/// <exception cref="System.IO.IOException"></exception>
			internal void List()
			{
				IDictionary<string, string> args = new SortedDictionary<string, string>();
				if (this.prefix.Length > 0)
				{
					args.Put("prefix", this.prefix);
				}
				if (!this.entries.IsEmpty())
				{
					args.Put("marker", this.prefix + this.entries[this.entries.Count - 1]);
				}
				for (int curAttempt = 0; curAttempt < this._enclosing.maxAttempts; curAttempt++)
				{
					HttpURLConnection c = this._enclosing.Open("GET", this.bucket, string.Empty, args
						);
					this._enclosing.Authorize(c);
					switch (HttpSupport.Response(c))
					{
						case HttpURLConnection.HTTP_OK:
						{
							this.truncated = false;
							this.data = null;
							XMLReader xr;
							try
							{
								xr = XMLReaderFactory.CreateXMLReader();
							}
							catch (SAXException)
							{
								throw new IOException(JGitText.Get().noXMLParserAvailable);
							}
							xr.SetContentHandler(this);
							InputStream @in = c.GetInputStream();
							try
							{
								xr.Parse(new InputSource(@in));
							}
							catch (SAXException parsingError)
							{
								IOException p;
								p = new IOException(MessageFormat.Format(JGitText.Get().errorListing, this.prefix
									));
								Sharpen.Extensions.InitCause(p, parsingError);
								throw p;
							}
							finally
							{
								@in.Close();
							}
							return;
						}

						case HttpURLConnection.HTTP_INTERNAL_ERROR:
						{
							continue;
							goto default;
						}

						default:
						{
							throw this._enclosing.Error("Listing", this.prefix, c);
						}
					}
				}
				throw this._enclosing.MaxAttempts("Listing", this.prefix);
			}
开发者ID:nickname100,项目名称:monodevelop,代码行数:67,代码来源:AmazonS3.cs

示例3: ReadRef

			/// <exception cref="NGit.Errors.TransportException"></exception>
			private Ref ReadRef(SortedDictionary<string, Ref> avail, string rn)
			{
				string s;
				string @ref = WalkRemoteObjectDatabase.ROOT_DIR + rn;
				try
				{
					BufferedReader br = this.OpenReader(@ref);
					try
					{
						s = br.ReadLine();
					}
					finally
					{
						br.Close();
					}
				}
				catch (FileNotFoundException)
				{
					return null;
				}
				catch (IOException err)
				{
					throw new TransportException(this.GetURI(), MessageFormat.Format(JGitText.Get().transportExceptionReadRef
						, @ref), err);
				}
				if (s == null)
				{
					throw new TransportException(this.GetURI(), MessageFormat.Format(JGitText.Get().transportExceptionEmptyRef
						, rn));
				}
				if (s.StartsWith("ref: "))
				{
					string target = Sharpen.Runtime.Substring(s, "ref: ".Length);
					Ref r = avail.Get(target);
					if (r == null)
					{
						r = this.ReadRef(avail, target);
					}
					if (r == null)
					{
						r = new ObjectIdRef.Unpeeled(RefStorage.NEW, target, null);
					}
					r = new SymbolicRef(rn, r);
					avail.Put(r.GetName(), r);
					return r;
				}
				if (ObjectId.IsId(s))
				{
					Ref r = new ObjectIdRef.Unpeeled(this.Loose(avail.Get(rn)), rn, ObjectId.FromString
						(s));
					avail.Put(r.GetName(), r);
					return r;
				}
				throw new TransportException(this.GetURI(), MessageFormat.Format(JGitText.Get().transportExceptionBadRef
					, rn, s));
			}
开发者ID:nickname100,项目名称:monodevelop,代码行数:57,代码来源:TransportAmazonS3.cs

示例4: Authorize

		/// <exception cref="System.IO.IOException"></exception>
		private void Authorize(HttpURLConnection c)
		{
			IDictionary<string, IList<string>> reqHdr = c.GetRequestProperties();
			SortedDictionary<string, string> sigHdr = new SortedDictionary<string, string>();
			foreach (KeyValuePair<string, IList<string>> entry in reqHdr.EntrySet())
			{
				string hdr = entry.Key;
				if (IsSignedHeader(hdr))
				{
					sigHdr.Put(StringUtils.ToLowerCase(hdr), ToCleanString(entry.Value));
				}
			}
			StringBuilder s = new StringBuilder();
			s.Append(c.GetRequestMethod());
			s.Append('\n');
			s.Append(Remove(sigHdr, "content-md5"));
			s.Append('\n');
			s.Append(Remove(sigHdr, "content-type"));
			s.Append('\n');
			s.Append(Remove(sigHdr, "date"));
			s.Append('\n');
			foreach (KeyValuePair<string, string> e in sigHdr.EntrySet())
			{
				s.Append(e.Key);
				s.Append(':');
				s.Append(e.Value);
				s.Append('\n');
			}
			string host = c.GetURL().GetHost();
			s.Append('/');
			s.Append(Sharpen.Runtime.Substring(host, 0, host.Length - DOMAIN.Length - 1));
			s.Append(c.GetURL().AbsolutePath);
			string sec;
			try
			{
				Mac m = Mac.GetInstance(HMAC);
				m.Init(privateKey);
				sec = Base64.EncodeBytes(m.DoFinal(Sharpen.Runtime.GetBytesForString(s.ToString()
					, "UTF-8")));
			}
			catch (NoSuchAlgorithmException e_1)
			{
				throw new IOException(MessageFormat.Format(JGitText.Get().noHMACsupport, HMAC, e_1
					.Message));
			}
			catch (InvalidKeyException e_1)
			{
				throw new IOException(MessageFormat.Format(JGitText.Get().invalidKey, e_1.Message
					));
			}
			c.SetRequestProperty("Authorization", "AWS " + publicKey + ":" + sec);
		}
开发者ID:nickname100,项目名称:monodevelop,代码行数:53,代码来源:AmazonS3.cs

示例5: RemoveReturnStatus

        public SortedDictionary<Number640, byte> RemoveReturnStatus(Number640 from, Number640 to, IPublicKey publicKey)
        {
		    var rLock = RangeLock.Lock(from, to);
		    try
            {
			    var tmp = _backend.SubMap(from, to, -1, true);
			    var result = new SortedDictionary<Number640, byte>();
			    foreach (var key in tmp.Keys)
                {
				    var pair = Remove(key, publicKey, false);
				    result.Put(key, (byte) Convert.ToInt32(pair.Element1)); // TODO check if works
			    }
			    return result;
		    }
            finally
            {
			    rLock.Unlock();
		    }
	    }
开发者ID:pacificIT,项目名称:TomP2P.NET,代码行数:19,代码来源:StorageLayer.cs

示例6: RemoteCheckpointDocID

        // Pusher overrides this to implement the .createTarget option
        /// <summary>This is the _local document ID stored on the remote server to keep track of state.
        ///     </summary>
        /// <remarks>
        /// This is the _local document ID stored on the remote server to keep track of state.
        /// Its ID is based on the local database ID (the private one, to make the result unguessable)
        /// and the remote database's URL.
        /// </remarks>
        internal string RemoteCheckpointDocID(string localUUID)
        {
            if (LocalDatabase == null) {
                return null;
            }

            // canonicalization: make sure it produces the same checkpoint id regardless of
            // ordering of filterparams / docids
            IDictionary<String, Object> filterParamsCanonical = null;
            if (FilterParams != null) {
                filterParamsCanonical = new SortedDictionary<String, Object>(FilterParams);
            }

            List<String> docIdsSorted = null;
            if (DocIds != null) {
                docIdsSorted = new List<String>(DocIds);
                docIdsSorted.Sort();
            }

            // use a treemap rather than a dictionary for purposes of canonicalization
            var spec = new SortedDictionary<String, Object>();
            spec.Put("localUUID", localUUID);
            spec.Put("push", !IsPull);
            spec.Put("continuous", Continuous);

            if (Filter != null) {
                spec.Put("filter", Filter);
            }
            if (filterParamsCanonical != null) {
                spec.Put("filterParams", filterParamsCanonical);
            }
            if (docIdsSorted != null) {
                spec.Put("docids", docIdsSorted);
            }

            string remoteUUID;
            var hasValue = Options.TryGetValue<string>(ReplicationOptionsDictionary.REMOTE_UUID_KEY, out remoteUUID);
            if (hasValue) {
                spec["remoteURL"] = remoteUUID;
            } else {
                spec["remoteURL"] = RemoteUrl.AbsoluteUri;
            }

            IEnumerable<byte> inputBytes = null;
            try {
                inputBytes = Manager.GetObjectMapper().WriteValueAsBytes(spec);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

            return Misc.HexSHA1Digest(inputBytes);
        }
开发者ID:Steven-Mark-Ford,项目名称:couchbase-lite-net,代码行数:60,代码来源:Replication.cs

示例7: TestTerms

        public void TestTerms()
        {
            Random random = Random();
            int num = AtLeast(10000);
#pragma warning disable 612, 618
            IComparer<BytesRef> comparator = random.nextBoolean() ? BytesRef.UTF8SortedAsUnicodeComparer : BytesRef.UTF8SortedAsUTF16Comparer;
#pragma warning restore 612, 618
            IDictionary<BytesRef, KeyValuePair<long, BytesRef>> sorted = new SortedDictionary<BytesRef, KeyValuePair<long, BytesRef>>(comparator); //new TreeMap<>(comparator);
            IDictionary<BytesRef, long> sortedWithoutPayload = new SortedDictionary<BytesRef, long>(comparator); //new TreeMap<>(comparator);
            IDictionary<BytesRef, KeyValuePair<long, ISet<BytesRef>>> sortedWithContext = new SortedDictionary<BytesRef, KeyValuePair<long, ISet<BytesRef>>>(comparator); //new TreeMap<>(comparator);
            IDictionary<BytesRef, KeyValuePair<long, KeyValuePair<BytesRef, ISet<BytesRef>>>> sortedWithPayloadAndContext = new SortedDictionary<BytesRef, KeyValuePair<long, KeyValuePair<BytesRef, ISet<BytesRef>>>>(comparator); //new TreeMap<>(comparator);
            Input[] unsorted = new Input[num];
            Input[] unsortedWithoutPayload = new Input[num];
            Input[] unsortedWithContexts = new Input[num];
            Input[] unsortedWithPayloadAndContext = new Input[num];
            ISet<BytesRef> ctxs;
            for (int i = 0; i < num; i++)
            {
                BytesRef key2;
                BytesRef payload;
                ctxs = new HashSet<BytesRef>();
                do
                {
                    key2 = new BytesRef(TestUtil.RandomUnicodeString(random));
                    payload = new BytesRef(TestUtil.RandomUnicodeString(random));
                    for (int j = 0; j < AtLeast(2); j++)
                    {
                        ctxs.add(new BytesRef(TestUtil.RandomUnicodeString(random)));
                    }
                } while (sorted.ContainsKey(key2));
                long value = random.Next();
                sortedWithoutPayload.Put(key2, value);
                sorted.Put(key2, new KeyValuePair<long, BytesRef>(value, payload));
                sortedWithContext.Put(key2, new KeyValuePair<long, ISet<BytesRef>>(value, ctxs));
                sortedWithPayloadAndContext.Put(key2, new KeyValuePair<long, KeyValuePair<BytesRef, ISet<BytesRef>>>(value, new KeyValuePair<BytesRef, ISet<BytesRef>>(payload, ctxs)));
                unsorted[i] = new Input(key2, value, payload);
                unsortedWithoutPayload[i] = new Input(key2, value);
                unsortedWithContexts[i] = new Input(key2, value, ctxs);
                unsortedWithPayloadAndContext[i] = new Input(key2, value, payload, ctxs);
            }

            // test the sorted iterator wrapper with payloads
            IInputIterator wrapper = new SortedInputIterator(new InputArrayIterator(unsorted), comparator);
            IEnumerator<KeyValuePair<BytesRef, KeyValuePair<long, BytesRef>>> expected = sorted.GetEnumerator();
            while (expected.MoveNext())
            {
                KeyValuePair<BytesRef, KeyValuePair<long, BytesRef>> entry = expected.Current;


                assertEquals(entry.Key, wrapper.Next());
                assertEquals(Convert.ToInt64(entry.Value.Key), wrapper.Weight);
                assertEquals(entry.Value.Value, wrapper.Payload);
            }
            assertNull(wrapper.Next());

            // test the sorted iterator wrapper with contexts
            wrapper = new SortedInputIterator(new InputArrayIterator(unsortedWithContexts), comparator);
            IEnumerator<KeyValuePair<BytesRef, KeyValuePair<long, ISet<BytesRef>>>> actualEntries = sortedWithContext.GetEnumerator();
            while (actualEntries.MoveNext())
            {
                KeyValuePair<BytesRef, KeyValuePair<long, ISet<BytesRef>>> entry = actualEntries.Current;
                assertEquals(entry.Key, wrapper.Next());
                assertEquals(Convert.ToInt64(entry.Value.Key), wrapper.Weight);
                ISet<BytesRef> actualCtxs = entry.Value.Value;
                assertEquals(actualCtxs, wrapper.Contexts);
            }
            assertNull(wrapper.Next());

            // test the sorted iterator wrapper with contexts and payload
            wrapper = new SortedInputIterator(new InputArrayIterator(unsortedWithPayloadAndContext), comparator);
            IEnumerator<KeyValuePair<BytesRef, KeyValuePair<long, KeyValuePair<BytesRef, ISet<BytesRef>>>>> expectedPayloadContextEntries = sortedWithPayloadAndContext.GetEnumerator();
            while (expectedPayloadContextEntries.MoveNext())
            {
                KeyValuePair<BytesRef, KeyValuePair<long, KeyValuePair<BytesRef, ISet<BytesRef>>>> entry = expectedPayloadContextEntries.Current;
                assertEquals(entry.Key, wrapper.Next());
                assertEquals(Convert.ToInt64(entry.Value.Key), wrapper.Weight);
                ISet<BytesRef> actualCtxs = entry.Value.Value.Value;
                assertEquals(actualCtxs, wrapper.Contexts);
                BytesRef actualPayload = entry.Value.Value.Key;
                assertEquals(actualPayload, wrapper.Payload);
            }
            assertNull(wrapper.Next());

            // test the unsorted iterator wrapper with payloads
            wrapper = new UnsortedInputIterator(new InputArrayIterator(unsorted));
            IDictionary<BytesRef, KeyValuePair<long, BytesRef>> actual = new SortedDictionary<BytesRef, KeyValuePair<long, BytesRef>>(); //new TreeMap<>();
            BytesRef key;
            while ((key = wrapper.Next()) != null)
            {
                long value = wrapper.Weight;
                BytesRef payload = wrapper.Payload;
                actual.Put(BytesRef.DeepCopyOf(key), new KeyValuePair<long, BytesRef>(value, BytesRef.DeepCopyOf(payload)));
            }
            assertEquals(sorted, actual);

            // test the sorted iterator wrapper without payloads
            IInputIterator wrapperWithoutPayload = new SortedInputIterator(new InputArrayIterator(unsortedWithoutPayload), comparator);
            IEnumerator<KeyValuePair<BytesRef, long>> expectedWithoutPayload = sortedWithoutPayload.GetEnumerator();
            while (expectedWithoutPayload.MoveNext())
            {
//.........这里部分代码省略.........
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:101,代码来源:TestInputIterator.cs

示例8: GetFieldMap

		public virtual IDictionary<string, IList<string>> GetFieldMap()
		{
			IDictionary<string, IList<string>> result = new SortedDictionary<string, IList<string
				>>(string.CaseInsensitiveOrder);
			// android-changed
			foreach (KeyValuePair<string, List<string>> next in keyTable.EntrySet())
			{
				IList<string> v = next.Value;
				result.Put(next.Key, Sharpen.Collections.UnmodifiableList(v));
			}
			return Sharpen.Collections.UnmodifiableMap(result);
		}
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:12,代码来源:URLConnection.cs


注:本文中的SortedDictionary.Put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。