public void TestPutNoDuplicate()
        {
            testName = "TestPutNoDuplicate";
            SetUpTest(true);
            string dbFileName = testHome + "/" + testName + ".db";

            HashDatabaseConfig hashConfig =
                new HashDatabaseConfig();

            hashConfig.Creation   = CreatePolicy.ALWAYS;
            hashConfig.Duplicates = DuplicatesPolicy.SORTED;
            hashConfig.TableSize  = 20;
            HashDatabase hashDB = HashDatabase.Open(dbFileName, hashConfig);

            DatabaseEntry key, data;

            for (int i = 1; i <= 10; i++)
            {
                key  = new DatabaseEntry(BitConverter.GetBytes(i));
                data = new DatabaseEntry(BitConverter.GetBytes(i));
                hashDB.PutNoDuplicate(key, data);
            }

            Assert.IsTrue(hashDB.Exists(
                              new DatabaseEntry(BitConverter.GetBytes((int)5))));

            hashDB.Close();
        }
Example #2
0
        /// <summary>
        /// Gets the index payload for a given atom.
        /// </summary>
        /// <param name="atom">The internal representation belonging to the atom.</param>
        /// <returns>
        /// The index payload for the given atom.
        /// </returns>
        public IndexPayload GetPayload(long atom)
        {
            var key = new DatabaseEntry(Util.Encoding.DbEncode(atom));

            if (m_db.Exists(key))
            {
                var kvPair = m_db.Get(key);
                return(new IndexPayload(kvPair.Value.Data));
            }
            else
            {
                throw new ArgumentOutOfRangeException("atom", "No payload for given atom!");
            }
        }
Example #3
0
        /// <summary>
        /// Gets the external (or friendly) string representation belonging to a given integer
        /// used as internal representation by the database.
        /// </summary>
        /// <param name="value">The internal representation.</param>
        /// <returns>
        /// A string belonging to the given internal representation.
        /// </returns>
        public string GetExternalRepresentation(long value)
        {
            var key = new DatabaseEntry(Util.Encoding.DbEncode(value));

            //
            // if this particular internal representation does not already exist in the dictionary
            // we throw an argument exception.

            if (m_dbLong2Str.Exists(key))
            {
                var kvPair = m_dbLong2Str.Get(key);
                return(Util.Encoding.DbDecodeString(kvPair.Value.Data));
            }
            else
            {
                throw new ArgumentOutOfRangeException("value", "No such internal representation!");
            }
        }
Example #4
0
        /// <summary>
        /// Gets the internal representation used by the database for a given string value.
        /// </summary>
        /// <param name="value">The string value.</param>
        /// <returns>
        /// An integer which is the internal representation for the given string.
        /// </returns>
        public long GetInternalRepresentation(string value)
        {
            var key = new DatabaseEntry(Util.Encoding.DbEncode(value));

            //
            // if this string already exists in the dictionary we simply retrieve the internal
            // representation that belongs to it. if not, we assign an internal representation to
            // it on the fly and insert it into the dictionary. whatever case we are in is
            // indistinguishable to the caller.

            if (m_dbStr2Long.Exists(key))
            {
                var kvPair = m_dbStr2Long.Get(key);
                return(Util.Encoding.DbDecodeInt64(kvPair.Value.Data));
            }
            else
            {
                var next = m_next++;
                Insert(next, value);
                return(next);
            }
        }