예제 #1
0
            /// <summary>
            /// Compare this Node with node2 first comparing dataPrefix_ then sessionNo_.
            /// </summary>
            ///
            /// <param name="node2">The other Node to compare.</param>
            /// <returns>True if this node is less than node2.</returns>
            public bool lessThan(DigestTree.Node node2)
            {
                // We compare the Unicode strings which is OK because it has the same sort
                // order as the UTF-8 encoding: http://en.wikipedia.org/wiki/UTF-8#Advantages
                // "Sorting a set of UTF-8 encoded strings as strings of unsigned bytes
                // yields the same order as sorting the corresponding Unicode strings
                // lexicographically by codepoint."
                int prefixComparison = String.CompareOrdinal(dataPrefix_, node2.dataPrefix_);

                if (prefixComparison != 0)
                {
                    return(prefixComparison < 0);
                }

                return(sessionNo_ < node2.sessionNo_);
            }
예제 #2
0
        /// <summary>
        /// Update the digest tree and recompute the root digest.  If the combination
        /// of dataPrefix and sessionNo already exists in the tree then update its
        /// sequenceNo (only if the given sequenceNo is newer), otherwise add a new node.
        /// </summary>
        ///
        /// <param name="dataPrefix">The name prefix. This is encoded as UTF-8 to digest.</param>
        /// <param name="sessionNo">The session number.</param>
        /// <param name="sequenceNo">The new sequence number.</param>
        /// <returns>True if the digest tree is updated, false if not (because the
        /// given sequenceNo is not newer than the existing sequence number).</returns>
        public bool update(String dataPrefix, long sessionNo,
                           long sequenceNo)
        {
            int nodeIndex = find(dataPrefix, sessionNo);

            ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(DigestTree).FullName).log(ILOG.J2CsMapping.Util.Logging.Level.FINE,
                                                                                            "{0}, {1}", new Object[] { dataPrefix, sessionNo });
            ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(DigestTree).FullName).log(ILOG.J2CsMapping.Util.Logging.Level.FINE,
                                                                                            "DigestTree.update session {0}, nodeIndex {1}",
                                                                                            new Object[] { sessionNo, nodeIndex });
            if (nodeIndex >= 0)
            {
                // Only update to a  newer status.
                if (digestNode_[nodeIndex].getSequenceNo() < sequenceNo)
                {
                    digestNode_[nodeIndex].setSequenceNo(sequenceNo);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(DigestTree).FullName).log(ILOG.J2CsMapping.Util.Logging.Level.FINE,
                                                                                                "new comer {0}, session {1}, sequence {2}",
                                                                                                new Object[] { dataPrefix, sessionNo, sequenceNo });
                // Insert into digestnode_ sorted.
                DigestTree.Node temp = new DigestTree.Node(dataPrefix, sessionNo, sequenceNo);
                // Find the index of the first node where it is not less than temp.
                int i = 0;
                while (i < digestNode_.Count)
                {
                    if (!digestNode_[i].lessThan(temp))
                    {
                        break;
                    }
                    ++i;
                }
                digestNode_.Insert(i, temp);
            }

            recomputeRoot();
            return(true);
        }
예제 #3
0
        /// <summary>
        /// Update the digest tree and recompute the root digest.  If the combination
        /// of dataPrefix and sessionNo already exists in the tree then update its
        /// sequenceNo (only if the given sequenceNo is newer), otherwise add a new node.
        /// </summary>
        ///
        /// <param name="dataPrefix">The name prefix. This is encoded as UTF-8 to digest.</param>
        /// <param name="sessionNo">The session number.</param>
        /// <param name="sequenceNo">The new sequence number.</param>
        /// <returns>True if the digest tree is updated, false if not (because the
        /// given sequenceNo is not newer than the existing sequence number).</returns>
        public bool update(String dataPrefix, long sessionNo,
				long sequenceNo)
        {
            int nodeIndex = find(dataPrefix, sessionNo);
            ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(DigestTree).FullName).log(ILOG.J2CsMapping.Util.Logging.Level.FINE,
                    "{0}, {1}", new Object[] { dataPrefix, sessionNo });
            ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(DigestTree).FullName).log(ILOG.J2CsMapping.Util.Logging.Level.FINE,
                    "DigestTree.update session {0}, nodeIndex {1}",
                    new Object[] { sessionNo, nodeIndex });
            if (nodeIndex >= 0) {
                // Only update to a  newer status.
                if (digestNode_[nodeIndex].getSequenceNo() < sequenceNo)
                    digestNode_[nodeIndex].setSequenceNo(sequenceNo);
                else
                    return false;
            } else {
                ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(DigestTree).FullName).log(ILOG.J2CsMapping.Util.Logging.Level.FINE,
                        "new comer {0}, session {1}, sequence {2}",
                        new Object[] { dataPrefix, sessionNo, sequenceNo });
                // Insert into digestnode_ sorted.
                DigestTree.Node  temp = new DigestTree.Node (dataPrefix, sessionNo, sequenceNo);
                // Find the index of the first node where it is not less than temp.
                int i = 0;
                while (i < digestNode_.Count) {
                    if (!digestNode_[i].lessThan(temp))
                        break;
                    ++i;
                }
                digestNode_.Insert(i, temp);
            }

            recomputeRoot();
            return true;
        }