コード例 #1
0
        public void BasicInterning()
        {
            var interner   = new LookasideStringInterner(StringComparer.OrdinalIgnoreCase, 1);
            int nullIndex  = interner.Intern(null);
            int emptyIndex = interner.Intern(String.Empty);
            int strIndex   = interner.Intern("abc123def456");

            Assert.AreEqual(interner.Intern(null), nullIndex);
            Assert.AreEqual(interner.Intern(String.Empty), emptyIndex);
            Assert.AreEqual(interner.Intern("abc123def456"), strIndex);

            Assert.AreEqual(interner.GetString(nullIndex), null);
            Assert.AreEqual(interner.GetString(emptyIndex), String.Empty);
            Assert.AreEqual(interner.GetString(strIndex), "abc123def456");
        }
コード例 #2
0
        public void Serialization()
        {
            var interner   = new LookasideStringInterner(StringComparer.OrdinalIgnoreCase, 1);
            int nullIndex  = interner.Intern(null);
            int emptyIndex = interner.Intern(String.Empty);
            int strIndex   = interner.Intern("abc123def456");

            MemoryStream          stream          = new MemoryStream();
            INodePacketTranslator writetranslator = NodePacketTranslator.GetWriteTranslator(stream);

            interner.Translate(writetranslator);

            INodePacketTranslator readtranslator = NodePacketTranslator.GetReadTranslator(stream, null);
            var newInterner = new LookasideStringInterner(readtranslator);

            Assert.AreEqual(newInterner.GetString(nullIndex), null);
            Assert.AreEqual(newInterner.GetString(emptyIndex), String.Empty);
            Assert.AreEqual(newInterner.GetString(strIndex), "abc123def456");
        }
コード例 #3
0
        public void Empty()
        {
            var interner = new LookasideStringInterner(StringComparer.OrdinalIgnoreCase, 1);

            interner.GetString(0);
        }