Click here to Skip to main content
Click here to Skip to main content
Articles » Database » NoSQL » General » Downloads
 
Add your own
alternative version

RaptorDB - the Key Value Store

, 22 Jan 2012
Smallest, fastest embedded nosql persisted dictionary using b+tree or MurMur hash indexing. (Now with Hybrid WAH bitmap indexes)
RaptorDB_v1.0.zip
RaptorDB
testing
RaptorDB_v1.1.zip
Indexes
Storage
Views
RaptorDB_v1.2.zip
RaptorDB_v1.3.zip
RaptorDB_v1.4.1.zip
Properties
RaptorDB_v1.4.zip
RaptorDB_v1.5.1.zip
RaptorDB_v1.5.2.zip
RaptorDB_v1.5.zip
RaptorDB_v1.6.zip
RaptorDB_v1.7.5.zip
UnitTests
Properties
UnitTests.nunit
RaptorDB_v1.7.zip
_svn
all-wcprops
dir-prop-base
entries
prop-base
props
text-base
AssemblyInfo.cs.svn-base
tmp
prop-base
props
text-base
UnitTests.nunit
RaptorDB_v1.8.zip
DataTypes
UnitTests.nunit
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RaptorDB
{
    public interface IRDBDataType<T> : IComparable<T>, IGetBytes<T>, IEqualityComparer<T>, IEquatable<T> 
    {
    }
    
    //------------------------------------------------------------------------------------------------------------------

    public interface IGetBytes<T>
    {
        byte[] GetBytes();
        T GetObject(byte[] buffer, int offset, int count);
    }

    //----------------------------------------------------------------------------------------------------

    public class rdbByteArray : IRDBDataType<rdbByteArray>
    {
        public rdbByteArray()
        {

        }

        public rdbByteArray(byte[] key)
        {
            val = key;
        }
        public byte[] val;

        public int CompareTo(rdbByteArray obj)
        {
            return Helper.CompareUnSafe(val, obj.val);
        }

        public byte[] GetBytes()
        {
            return val;
        }

        public bool Equals(rdbByteArray a, rdbByteArray b)
        {
            if (a == null || b == null)
                return a == b;
            if (a.val.Length != b.val.Length)
                return false;
            int i = Helper.CompareUnSafe(a.val, b.val);
            return i==0?true:false;
        }

        public int GetHashCode(rdbByteArray obj)
        {
            if (obj == null)
                throw new ArgumentNullException();
            int iHash = 0;
            for (int i = 0; i < obj.val.Length; ++i)
                iHash ^= (obj.val[i] << ((0x03 & i) << 3));
            return iHash;
        }

        public bool Equals(rdbByteArray other)
        {
            if (other == null)
                return false;
            if (this.val.Length != other.val.Length)
                return false;
            int i = Helper.CompareUnSafe(this.val, other.val);
            return i == 0 ? true : false;
        }

        public rdbByteArray GetObject(byte[] buffer, int offset, int count)
        {
            byte[] b = new byte[count];
            Buffer.BlockCopy(buffer, offset, b, 0, count);
            return new rdbByteArray(b);
        }

        public override bool Equals(object obj)
        {
            int i = Helper.CompareUnSafe(this.val, ((rdbByteArray)obj).val);
            return i == 0 ? true : false;
        }

        public override int GetHashCode()
        {
            return this.GetHashCode(this);
        }
    }

    //----------------------------------------------------------------------------------------------------

    public class rdbInt : IRDBDataType<rdbInt>
    {
        public rdbInt()
        {

        }
        public rdbInt(int i)
        {
            _i = i;
        }
        public rdbInt(uint i)
        {
            _i = (int)i;
        }
        private int _i;

        public int CompareTo(rdbInt other)
        {
            return _i.CompareTo(other._i);
        }

        public byte[] GetBytes()
        {
            return Helper.GetBytes(_i, false);
        }

        public bool Equals(rdbInt x, rdbInt y)
        {
            return x._i == y._i;
        }

        public int GetHashCode(rdbInt obj)
        {
            return obj._i;
        }

        public bool Equals(rdbInt other)
        {
            return this._i == other._i;
        }

        public rdbInt GetObject(byte[] buffer, int offset, int count)
        {
            return new rdbInt(Helper.ToInt32(buffer, offset));
        }

        public override bool Equals(object obj)
        {
            return this._i == ((rdbInt)obj)._i;
        }

        public override int GetHashCode()
        {
            return _i;
        }
    }

    //----------------------------------------------------------------------------------------------------

    public class rdbLong : IRDBDataType<rdbLong>
    {
        public rdbLong()
        {

        }
        public rdbLong(long i)
        {
            _i = i;
        }
        private long _i;

        public int CompareTo(rdbLong other)
        {
            return _i.CompareTo(other._i);
        }

        public byte[] GetBytes()
        {
            return Helper.GetBytes(_i, false);
        }

        public bool Equals(rdbLong x, rdbLong y)
        {
            return x._i == y._i;
        }

        public int GetHashCode(rdbLong obj)
        {
            return obj._i.GetHashCode();
        }

        public bool Equals(rdbLong other)
        {
            return this._i == other._i;
        }

        public rdbLong GetObject(byte[] buffer, int offset, int count)
        {
            return new rdbLong(Helper.ToInt64(buffer, offset));
        }

        public override bool Equals(object obj)
        {
            return this._i == ((rdbLong)obj)._i;
        }

        public override int GetHashCode()
        {
            return _i.GetHashCode();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mehdi Gholam
Architect
United Kingdom United Kingdom
Mehdi first started programming when he was 8 on BBC+128k machine in 6512 processor language, after various hardware and software changes he eventually came across .net and c# which he has been using since v1.0.
He is formally educated as a system analyst Industrial engineer, but his programming passion continues.
 
* Mehdi is the 5th person to get 6 out of 7 Platinums on CodeProject (13th Jan'12)

| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 23 Jan 2012
Article Copyright 2011 by Mehdi Gholam
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid