コード例 #1
0
        public void KeyComparer_equals_identifys_matches()
        {
            KeyComparer keyComparer = new KeyComparer();

            Key key1 = new Key(typeof(ViewModel), typeof(ViewModel));

            keyComparer.Equals(key1, key1).MustBeTrue();

            Key key2 = new Key(typeof(ViewModel));

            keyComparer.Equals(key2, key2).MustBeTrue();

            keyComparer.Equals(key1, key2).MustBeFalse();
        }
コード例 #2
0
        protected virtual bool IsPersistentWithSameIdAs(EntityVersioned <TKey> compareTo)
        {
            if (compareTo == null)
            {
                throw new ArgumentNullException(nameof(compareTo));
            }

            return(!IsTransient && !compareTo.IsTransient && KeyComparer.Equals(Id, compareTo.Id));
        }
コード例 #3
0
        /// <summary>
        /// Create a new instance of SortedDeque with the given comparer.
        /// </summary>
        public SortedDeque(int capacity, KeyComparer <T> comparer)
        {
            if (capacity <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(capacity));
            }
            this._comparer = comparer.Equals(default(KeyComparer <T>)) ? throw new ArgumentNullException(nameof(comparer)) : comparer;
            var cap = BitUtil.FindNextPositivePowerOfTwo(capacity);

            _buffer = new T[cap];
            // capacity is always a power of two and we use bitshift instead of modulo
            _bufferMask = _buffer.Length - 1;
        }
コード例 #4
0
ファイル: Equals.cs プロジェクト: run00/Versioning
        public void WhenPropertiesComparedAreNotEqual_ShouldReturnFalse()
        {
            //Arrange
            var comparer = new KeyComparer<TestPoco, int>(f => f.Id) as IEqualityComparer<TestPoco>;
            var one = new TestPoco() { Id = 1 };
            var two = new TestPoco() { Id = 2 };

            //Act
            var result = comparer.Equals(one, two);

            //Assert
            Assert.IsFalse(result);
        }
コード例 #5
0
ファイル: ProgressiveLookup.cs プロジェクト: NN---/Theraot
        public bool Contains(TKey key)
        {
            if (_cache.ContainsKey(key))
            {
                return(true);
            }
            return(ProgressorWhere(Check).Any());

            bool Check(IGrouping <TKey, T> item)
            {
                return(KeyComparer.Equals(key, item.Key));
            }
        }
コード例 #6
0
ファイル: ProgressiveLookup.cs プロジェクト: NN---/Theraot
        public bool TryGetValue(TKey key, out IGrouping <TKey, T> value)
        {
            if (_cache.TryGetValue(key, out value))
            {
                return(true);
            }
            foreach (var found in ProgressorWhere(Check))
            {
                value = found;
                return(true);
            }
            return(false);

            bool Check(IGrouping <TKey, T> item)
            {
                return(KeyComparer.Equals(key, item.Key));
            }
        }
コード例 #7
0
        /// <summary>
        ///     Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <param name="other">
        ///     An object to compare with this object.
        /// </param>
        /// <returns>
        ///     <c>true</c> if the current object is equal to the <paramref name="other" /> parameter, otherwise <c>false</c>.
        /// </returns>
        public bool Equals(EntitySpec other)
        {
            if (other == null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            if (!KeyComparer.Equals(this.key, other.key))
            {
                return(false);
            }

            return(string.Compare(this.tableName, other.tableName, StringComparison.Ordinal) == 0 &&
                   string.Compare(this.ns ?? string.Empty, other.ns ?? string.Empty, StringComparison.Ordinal) == 0);
        }
コード例 #8
0
        /// <summary>
        ///		No business key, any 2 instances with same Ids considered equal
        /// </summary>
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(this, obj))
            {
                return(true);
            }

            if (!(obj is EntityVersioned <TKey> thatEntity))
            {
                return(false);
            }

            var thisType = GetTypeUnproxied();
            var thatType = thatEntity.GetTypeUnproxied();

            if (thisType != thatType)
            {
                return(false);
            }

            return(KeyComparer.Equals(Id, thatEntity.Id));
        }
コード例 #9
0
            public override bool Equals(object obj)
            {
                var that = obj as EntityPropertyInfo;

                return(that != null && KeyComparer.Equals(this.Name, that.Name) && this.PropertyType == that.PropertyType);
            }
 protected override ReadOnlyObservableGroup <TSource, TKey> FindGroup(TKey key)
 {
     return(_groups.SingleOrDefault(g => KeyComparer.Equals(g.Key, key)));
 }
コード例 #11
0
ファイル: TestTableScanner.cs プロジェクト: andysoftdev/ht4n
        public void ScanTableRandomCells()
        {
            var random = new Random();
            const string Cf = "abcdefg";
            const int Count = 10000;
            using (var _table = EnsureTable("ScanTableRandomCells", Schema)) {
                var keys = new List<Key>(Count);
                using (var mutator = _table.CreateMutator()) {
                    for (var i = 0; i < Count; ++i) {
                        var key = new Key
                            {
                                Row = Guid.NewGuid().ToString(),
                                ColumnFamily = new string(new[] { Cf[random.Next(Cf.Length)] }),
                                ColumnQualifier = random.Next(Cf.Length).ToString(CultureInfo.InvariantCulture)
                            };
                        keys.Add(key);
                        mutator.Set(key, Encoding.GetBytes(key.Row));
                    }
                }

                for (var r = 0; r < 10; ++r) {
                    var countCells = 10 + random.Next(Count - 10);
                    var scanSpec = new ScanSpec();
                    foreach (var k in Shuffle(keys)) {
                        scanSpec.AddCell(k);
                        if (scanSpec.CellCount == countCells) {
                            break;
                        }
                    }

                    var comparer = new KeyComparer(false);
                    using (var scanner = _table.CreateScanner(scanSpec)) {
                        Assert.AreSame(scanSpec, scanner.ScanSpec);
                        var cell = new Cell();
                        var c = 0;
                        while( scanner.Move(cell) ) {
                            Assert.AreEqual(cell.Key.Row, Encoding.GetString(cell.Value));
                            Assert.IsTrue(comparer.Equals(scanSpec.Cells[c++], cell.Key));
                        }

                        Assert.AreEqual(scanSpec.CellCount, c);
                    }
                }

                for (var r = 0; r < 10; ++r) {
                    var countCells = 10 + random.Next(Count - 10);
                    var scanSpec = new ScanSpec();
                    foreach (var k in Shuffle(keys)) {
                        scanSpec.AddRow(k.Row);
                        if (scanSpec.RowCount == countCells) {
                            break;
                        }
                    }

                    using (var scanner = _table.CreateScanner(scanSpec)) {
                        Assert.AreSame(scanSpec, scanner.ScanSpec);
                        var cell = new Cell();
                        var c = 0;
                        while( scanner.Move(cell) ) {
                            Assert.AreEqual(cell.Key.Row, Encoding.GetString(cell.Value));
                            Assert.AreEqual(scanSpec.Rows[c++], cell.Key.Row);
                        }

                        Assert.AreEqual(scanSpec.RowCount, c);
                    }
                }

                for (var r = 0; r < 10; ++r) {
                    var rows = new HashSet<string>();
                    var countCells = 10 + random.Next(Count - 10);
                    var scanSpec = new ScanSpec(true);
                    foreach (var k in Shuffle(keys)) {
                        scanSpec.AddRow(k.Row);
                        rows.Add(k.Row);
                        if (scanSpec.RowCount == countCells) {
                            break;
                        }
                    }

                    using (var scanner = _table.CreateScanner(scanSpec)) {
                        Assert.AreSame(scanSpec, scanner.ScanSpec);
                        var cell = new Cell();
                        var c = 0;
                        while( scanner.Move(cell) ) {
                            Assert.AreEqual(cell.Key.Row, Encoding.GetString(cell.Value));
                            Assert.IsTrue(rows.Contains(cell.Key.Row));
                            ++c;
                        }

                        Assert.AreEqual(scanSpec.RowCount, c);
                    }
                }

                for (var r = 0; r < 10; ++r) {
                    var rows = new HashSet<string>();
                    var columnFamily = new string(new[] { Cf[random.Next(Cf.Length)] });
                    var columnQualifier = random.Next(Cf.Length).ToString(CultureInfo.InvariantCulture);
                    var countCells = 10 + random.Next(Count / 10);
                    var scanSpec = new ScanSpec { ScanAndFilter = true };
                    foreach (var k in Shuffle(keys).Where(k => k.ColumnFamily == columnFamily && k.ColumnQualifier == columnQualifier)) {
                        Assert.AreEqual(columnFamily, k.ColumnFamily);
                        Assert.AreEqual(columnQualifier, k.ColumnQualifier);
                        scanSpec.AddColumn(k.ColumnFamily + ":" + k.ColumnQualifier);
                        scanSpec.AddRow(k.Row);
                        rows.Add(k.Row);
                        if (scanSpec.RowCount == countCells) {
                            break;
                        }
                    }

                    using (var scanner = _table.CreateScanner(scanSpec)) {
                        Assert.AreSame(scanSpec, scanner.ScanSpec);
                        var cell = new Cell();
                        var c = 0;
                        while( scanner.Move(cell) ) {
                            Assert.AreEqual(cell.Key.Row, Encoding.GetString(cell.Value));
                            Assert.AreEqual(columnFamily, cell.Key.ColumnFamily);
                            Assert.AreEqual(columnQualifier, cell.Key.ColumnQualifier);
                            Assert.IsTrue(rows.Contains(cell.Key.Row));
                            ++c;
                        }

                        Assert.AreEqual(scanSpec.RowCount, c);
                    }
                }

                for (var r = 0; r < 10; ++r) {
                    var rows = new HashSet<string>();
                    var columnQualifier = random.Next(Cf.Length).ToString(CultureInfo.InvariantCulture);
                    var countCells = 10 + random.Next(Count / 10);
                    var scanSpec = new ScanSpec { ScanAndFilter = true };
                    foreach (var k in Shuffle(keys).Where(k => k.ColumnQualifier == columnQualifier)) {
                        Assert.AreEqual(columnQualifier, k.ColumnQualifier);
                        scanSpec.AddColumn(k.ColumnFamily + ":" + k.ColumnQualifier);
                        scanSpec.AddRow(k.Row);
                        rows.Add(k.Row);
                        if (scanSpec.RowCount == countCells) {
                            break;
                        }
                    }

                    using (var scanner = _table.CreateScanner(scanSpec)) {
                        Assert.AreSame(scanSpec, scanner.ScanSpec);
                        var cell = new Cell();
                        var c = 0;
                        while( scanner.Move(cell) ) {
                            Assert.AreEqual(cell.Key.Row, Encoding.GetString(cell.Value));
                            Assert.AreEqual(columnQualifier, cell.Key.ColumnQualifier);
                            Assert.IsTrue(rows.Contains(cell.Key.Row));
                            ++c;
                        }

                        Assert.AreEqual(scanSpec.RowCount, c);
                    }
                }

                using (var mutator = _table.CreateMutator()) {
                    var key = new Key { Row = "A", ColumnFamily = "a", ColumnQualifier = "1" };
                    mutator.Set(key, Encoding.GetBytes(key.Row));

                    key = new Key { Row = "B", ColumnFamily = "a", ColumnQualifier = "2" };
                    mutator.Set(key, Encoding.GetBytes(key.Row));

                    key = new Key { Row = "C", ColumnFamily = "c", ColumnQualifier = "3" };
                    mutator.Set(key, Encoding.GetBytes(key.Row));

                    key = new Key { Row = "D", ColumnFamily = "c", ColumnQualifier = "4" };
                    mutator.Set(key, Encoding.GetBytes(key.Row));

                    key = new Key { Row = "E", ColumnFamily = "b", ColumnQualifier = "5" };
                    mutator.Set(key, Encoding.GetBytes(key.Row));
                }

                {
                    var scanSpec = new ScanSpec { ScanAndFilter = true };
                    scanSpec.AddColumn("a:1");
                    scanSpec.AddColumn("a:2");
                    scanSpec.AddColumn("b:5");
                    scanSpec.AddColumn("c:3");
                    scanSpec.AddColumn("c:4");
                    scanSpec.AddRow("A");
                    scanSpec.AddRow("B");

                    using (var scanner = _table.CreateScanner(scanSpec)) {
                        Assert.AreSame(scanSpec, scanner.ScanSpec);
                        var cell = new Cell();
                        var c = 0;
                        while( scanner.Move(cell) ) {
                            Assert.AreEqual(cell.Key.Row, Encoding.GetString(cell.Value));
                            ++c;
                        }

                        Assert.AreEqual(scanSpec.RowCount, c);
                    }

                    scanSpec = new ScanSpec { ScanAndFilter = true };
                    scanSpec.AddColumn("a", "b:5", "c");
                    scanSpec.AddRow("A");
                    scanSpec.AddRow("C");
                    scanSpec.AddRow("E");

                    using (var scanner = _table.CreateScanner(scanSpec)) {
                        Assert.AreSame(scanSpec, scanner.ScanSpec);
                        var cell = new Cell();
                        var c = 0;
                        while( scanner.Move(cell) ) {
                            Assert.AreEqual(cell.Key.Row, Encoding.GetString(cell.Value));
                            ++c;
                        }

                        Assert.AreEqual(scanSpec.RowCount, c);
                    }
                }
            }
        }
コード例 #12
0
ファイル: Tree.cs プロジェクト: xstos/alithiatec
 public bool Equals(Tree <D> x, Tree <D> y)
 {
     return(KeyComparer.Equals(x.key, y.key));
 }
コード例 #13
0
        private void FirstPass(State state)
        {
            var skippedPoints = new HashSet <TPosition>(PositionComparer)
            {
                default(TPosition)
            };

            var activePoints    = new HashSet <TPosition>(PositionComparer);
            var newActivePoints = new HashSet <TPosition>(PositionComparer);
            var inactivePoints  = new HashSet <TPosition>(PositionComparer);

            var index     = 0;
            var testIndex = 0;
            var reference = default(TPosition);
            var key       = default(TKey);
            var shape     = default(Shape <TNode, TPosition, TKey>);

            while (skippedPoints.Count > 0)
            {
                reference = GetReference(skippedPoints);
                key       = Tesselation.Key(reference);
                shape     = state.CreateShape(key);

                activePoints.Clear();
                activePoints.Add(reference);

                while (activePoints.Count > 0)
                {
                    newActivePoints.Clear();

                    foreach (var v in activePoints)
                    {
                        skippedPoints.Remove(v);
                        inactivePoints.Add(v);
                        state.AddNodeToShape(shape, NodeFactory, v);

                        index = 0;
                        foreach (var vs in Tesselation.Surround(v))
                        {
                            testIndex = index++;
                            if (Tesselation.Valid(vs) && Tesselation.Tesselate(testIndex) && !(newActivePoints.Contains(vs) || inactivePoints.Contains(vs)))
                            {
                                if (KeyComparer.Equals(key, Tesselation.Key(vs)))
                                {
                                    newActivePoints.Add(vs);
                                }
                                else
                                {
                                    skippedPoints.Add(vs);
                                }
                            }
                        }
                    }

                    activePoints.Clear();
                    foreach (var item in newActivePoints)
                    {
                        activePoints.Add(item);
                    }
                }
            }
        }
コード例 #14
0
ファイル: TestKeyComparer.cs プロジェクト: andysoftdev/ht4n
        public void CompareIncludeTimestamp()
        {
            var comparer = new KeyComparer(true);
            var x        = new Key();

            Assert.IsFalse(comparer.Equals(x, null));
            Assert.IsFalse(comparer.Equals(null, x));

            var y = new Key();

            Assert.IsTrue(comparer.Equals(x, y));
            Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y));

            x.Row = "A";
            y.Row = "B";
            Assert.IsFalse(comparer.Equals(x, y));

            x.Row = "AB";
            y.Row = "AB";
            Assert.IsTrue(comparer.Equals(x, y));
            Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y));

            x.ColumnFamily = "A";
            y.ColumnFamily = "B";
            Assert.IsFalse(comparer.Equals(x, y));

            x.ColumnFamily = null;
            y.ColumnFamily = string.Empty;
            Assert.IsFalse(comparer.Equals(x, y));

            x.ColumnFamily = "AB";
            y.ColumnFamily = "AB";
            Assert.IsTrue(comparer.Equals(x, y));
            Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y));

            x.ColumnQualifier = "A";
            y.ColumnQualifier = "B";
            Assert.IsFalse(comparer.Equals(x, y));

            x.ColumnQualifier = null;
            y.ColumnQualifier = string.Empty;
            Assert.IsTrue(comparer.Equals(x, y));
            Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y));

            x.ColumnQualifier = "AB";
            y.ColumnQualifier = "AB";
            Assert.IsTrue(comparer.Equals(x, y));
            Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y));

            x.DateTime = new DateTime(2011, 1, 1, 1, 2, 3, DateTimeKind.Utc);
            y.DateTime = new DateTime(2011, 1, 1, 1, 2, 4, DateTimeKind.Utc);
            Assert.IsFalse(comparer.Equals(x, y));

            x.DateTime = new DateTime(2011, 1, 1, 1, 2, 3, DateTimeKind.Utc);
            y.DateTime = new DateTime(2011, 1, 1, 1, 2, 3, DateTimeKind.Utc);
            Assert.IsTrue(comparer.Equals(x, y));
            Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y));
        }
コード例 #15
0
 public bool Equals(KeyValuePair <TKey, TValue> x, KeyValuePair <TKey, TValue> y)
 {
     return(KeyComparer.Equals(x.Key, y.Key) && ValueComparer.Equals(x.Value, y.Value));
 }
コード例 #16
0
ファイル: TestKeyComparer.cs プロジェクト: bfmw/ht4n
        public void CompareIncludeTimestamp()
        {
            var comparer = new KeyComparer(true);
            var x = new Key();
            Assert.IsFalse(comparer.Equals(x, null));
            Assert.IsFalse(comparer.Equals(null, x));

            var y = new Key();
            Assert.IsTrue(comparer.Equals(x, y));
            Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y));

            x.Row = "A";
            y.Row = "B";
            Assert.IsFalse(comparer.Equals(x, y));

            x.Row = "AB";
            y.Row = "AB";
            Assert.IsTrue(comparer.Equals(x, y));
            Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y));

            x.ColumnFamily = "A";
            y.ColumnFamily = "B";
            Assert.IsFalse(comparer.Equals(x, y));

            x.ColumnFamily = null;
            y.ColumnFamily = string.Empty;
            Assert.IsFalse(comparer.Equals(x, y));

            x.ColumnFamily = "AB";
            y.ColumnFamily = "AB";
            Assert.IsTrue(comparer.Equals(x, y));
            Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y));

            x.ColumnQualifier = "A";
            y.ColumnQualifier = "B";
            Assert.IsFalse(comparer.Equals(x, y));

            x.ColumnQualifier = null;
            y.ColumnQualifier = string.Empty;
            Assert.IsTrue(comparer.Equals(x, y));
            Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y));

            x.ColumnQualifier = "AB";
            y.ColumnQualifier = "AB";
            Assert.IsTrue(comparer.Equals(x, y));
            Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y));

            x.DateTime = new DateTime(2011, 1, 1, 1, 2, 3, DateTimeKind.Utc);
            y.DateTime = new DateTime(2011, 1, 1, 1, 2, 4, DateTimeKind.Utc);
            Assert.IsFalse(comparer.Equals(x, y));

            x.DateTime = new DateTime(2011, 1, 1, 1, 2, 3, DateTimeKind.Utc);
            y.DateTime = new DateTime(2011, 1, 1, 1, 2, 3, DateTimeKind.Utc);
            Assert.IsTrue(comparer.Equals(x, y));
            Assert.AreEqual(comparer.GetHashCode(x), comparer.GetHashCode(y));
        }