コード例 #1
0
ファイル: TripleSerializer.cs プロジェクト: giedomak/TripleT
        /// <summary>
        /// Reads a single triple from the given binary input stream, using the given mini-bucket
        /// value in place of the given mini-bucket position.
        /// </summary>
        /// <param name="input">The input stream.</param>
        /// <param name="miniBucket">The mini-bucket position.</param>
        /// <param name="miniBucketValue">The mini-bucket value.</param>
        /// <returns>
        /// A single triple.
        /// </returns>
        public static Triple <Atom, Atom, Atom> Read(BinaryReader input, TriplePosition miniBucket, long miniBucketValue)
        {
            Atom s, p, o;

            if (miniBucket != TriplePosition.S)
            {
                s = new Atom(input.ReadInt64());
            }
            else
            {
                s = new Atom(miniBucketValue);
            }
            if (miniBucket != TriplePosition.P)
            {
                p = new Atom(input.ReadInt64());
            }
            else
            {
                p = new Atom(miniBucketValue);
            }
            if (miniBucket != TriplePosition.O)
            {
                o = new Atom(input.ReadInt64());
            }
            else
            {
                o = new Atom(miniBucketValue);
            }
            return(new Triple <Atom, Atom, Atom>(s, p, o));
        }
コード例 #2
0
ファイル: EdgeLabel.cs プロジェクト: giedomak/TripleT
 /// <summary>
 /// Initializes a new instance of the <see cref="EdgeLabel"/> class.
 /// </summary>
 /// <param name="left">The SAP of the left node connected to the edge.</param>
 /// <param name="right">The SAP of the right node connected to the edge.</param>
 /// <param name="sharedItem">The shared variable value between the two nodes connected by the edge.</param>
 /// <param name="positionLeft">The position of the shared variable in the SAP of the left node connected to the edge.</param>
 /// <param name="positionRight">The position of the shared variable in the SAP of the right node connected to the edge.</param>
 public EdgeLabel(Triple <TripleItem, TripleItem, TripleItem> left, Triple <TripleItem, TripleItem, TripleItem> right, TripleItem sharedItem, TriplePosition positionLeft, TriplePosition positionRight)
 {
     m_left       = left;
     m_right      = right;
     m_sharedItem = sharedItem;
     m_posLeft    = positionLeft;
     m_posRight   = positionRight;
 }
コード例 #3
0
ファイル: SortOrder.cs プロジェクト: giedomak/TripleT
        /// <summary>
        /// Initializes a new instance of the <see cref="SortOrder"/> struct.
        /// </summary>
        /// <param name="primary">The primary sorting position.</param>
        /// <param name="secondary">The secondary sorting position.</param>
        /// <param name="tertiary">The tertiary sorting position.</param>
        public SortOrder(TriplePosition primary, TriplePosition secondary, TriplePosition tertiary)
        {
            if (primary == secondary || primary == tertiary || secondary == tertiary)
            {
                throw new ArgumentException("All sorting positions must be unique!");
            }

            m_primary   = primary;
            m_secondary = secondary;
            m_tertiary  = tertiary;
        }
コード例 #4
0
ファイル: QueryPlan.cs プロジェクト: giedomak/TripleT
 /// <summary>
 /// Gets a descriptive scan operator for the given bucket, SAP, and optional starting atom.
 /// </summary>
 /// <param name="bucket">The bucket.</param>
 /// <param name="s">The s value.</param>
 /// <param name="p">The p value.</param>
 /// <param name="o">The o value.</param>
 /// <param name="startAtom">The starting atom.</param>
 /// <returns>
 /// A descriptive scan operator for the given bucket, SAP, and starting atom.
 /// </returns>
 public static Scan GetScan(TriplePosition bucket, object s, object p, object o, string startAtom = "")
 {
     if (s is string)
     {
         if (p is string)
         {
             if (o is string)
             {
                 return(GetScan(bucket, (string)s, (string)p, (string)o, startAtom));
             }
             else
             {
                 return(GetScan(bucket, (string)s, (string)p, (long)o, startAtom));
             }
         }
         else
         {
             if (o is string)
             {
                 return(GetScan(bucket, (string)s, (long)p, (string)o, startAtom));
             }
             else
             {
                 return(GetScan(bucket, (string)s, (long)p, (long)o, startAtom));
             }
         }
     }
     else
     {
         if (p is string)
         {
             if (o is string)
             {
                 return(GetScan(bucket, (long)s, (string)p, (string)o, startAtom));
             }
             else
             {
                 return(GetScan(bucket, (long)s, (string)p, (long)o, startAtom));
             }
         }
         else
         {
             if (o is string)
             {
                 return(GetScan(bucket, (long)s, (long)p, (string)o, startAtom));
             }
             else
             {
                 return(GetScan(bucket, (long)s, (long)p, (long)o, startAtom));
             }
         }
     }
 }
コード例 #5
0
ファイル: TripleCursor.cs プロジェクト: giedomak/TripleT
        /// <summary>
        /// Initializes a new instance of the <see cref="TripleCursor"/> class.
        /// </summary>
        /// <param name="input">The input stream.</param>
        /// <param name="miniBucket">The mini-bucket position.</param>
        /// <param name="miniBucketValue">The mini-bucket value.</param>
        /// <param name="seekToTriple">The optional position offset (measured in triples) to seek to before reading starts.</param>
        public TripleCursor(Stream input, TriplePosition miniBucket, long miniBucketValue, long seekToTriple = 0)
        {
            m_miniBucket      = miniBucket;
            m_miniBucketValue = miniBucketValue;
            m_tripleSize      = 16;

            m_reader = new BinaryReader(input);
            if (seekToTriple > 0)
            {
                m_reader.BaseStream.Seek(seekToTriple * m_tripleSize, SeekOrigin.Begin);
            }
            TryReadNext();
        }
コード例 #6
0
ファイル: TripleCursor.cs プロジェクト: giedomak/TripleT
        /// <summary>
        /// Initializes a new instance of the <see cref="TripleCursor"/> class.
        /// </summary>
        /// <param name="input">The input stream.</param>
        /// <param name="seekToTriple">The optional position offset (measured in triples) to seek to before reading starts.</param>
        public TripleCursor(Stream input, long seekToTriple = 0)
        {
            m_miniBucket = TriplePosition.None;
            m_tripleSize = 24;

            m_reader = new BinaryReader(input);
            if (seekToTriple > 0)
            {
                m_reader.BaseStream.Seek(seekToTriple * m_tripleSize, SeekOrigin.Begin);
            }

            //
            // prepare the next triple to output

            TryReadNext();
        }
コード例 #7
0
ファイル: Scan.cs プロジェクト: giedomak/TripleT
        /// <summary>
        /// Initializes a new instance of the <see cref="Scan"/> class.
        /// </summary>
        /// <param name="planOperator">The descriptive query plan operator that is the counterpart of this physical operator.</param>
        /// <param name="cursor">The triple cursor used for reading in triples.</param>
        /// <param name="inputSortOrder">The sort order the triples arrive in.</param>
        /// <param name="pattern">The Simple Access Pattern to match.</param>
        /// <param name="count">The number of triples to read.</param>
        public Scan(qp::Operator planOperator, TripleCursor cursor, SortOrder inputSortOrder, Triple <TripleItem, TripleItem, TripleItem> pattern, long count = -1)
        {
            m_planOperator = planOperator;
#if DEBUG
            m_planOperator.StartCPUWork();
#endif
            m_cursor     = cursor;
            m_inputOrder = inputSortOrder;
            m_pattern    = pattern;

            if (count > -1)
            {
                m_isMiniBucket = true;
                m_count        = count;
            }
            else
            {
                m_isMiniBucket = false;
            }

            //
            // identify the atoms in the given SAP to match

            m_patternAtoms = TriplePosition.None;
            if (m_pattern.S is Atom)
            {
                m_patternAtoms |= TriplePosition.S;
            }
            if (m_pattern.P is Atom)
            {
                m_patternAtoms |= TriplePosition.P;
            }
            if (m_pattern.O is Atom)
            {
                m_patternAtoms |= TriplePosition.O;
            }
#if DEBUG
            m_planOperator.StopCPUWork();
#endif
            //
            // prepare the next set of output bindings

            TryReadNext();
        }
コード例 #8
0
ファイル: Triple.cs プロジェクト: giedomak/TripleT
        /// <summary>
        /// Gets the <see cref="TripleT.Datastructures.TripleItem"/> at the specified position.
        /// </summary>
        public TripleItem this[TriplePosition index]
        {
            get
            {
                if (index == TriplePosition.S)
                {
                    return(m_s);
                }
                if (index == TriplePosition.P)
                {
                    return(m_p);
                }
                if (index == TriplePosition.O)
                {
                    return(m_o);
                }

                throw new ArgumentOutOfRangeException("index");
            }
        }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Scan"/> class.
 /// </summary>
 /// <param name="bucket">The triple bucket to scan from.</param>
 /// <param name="pattern">The SAP to scan for.</param>
 /// <param name="startAtom">The atom to start scanning at.</param>
 public Scan(TriplePosition bucket, Pattern pattern, string startAtom)
 {
     m_bucket    = bucket;
     m_pattern   = pattern;
     m_startAtom = startAtom;
 }
コード例 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Scan"/> class.
 /// </summary>
 /// <param name="bucket">The triple bucket to scan from.</param>
 /// <param name="pattern">The SAP to scan for.</param>
 public Scan(TriplePosition bucket, Pattern pattern)
     : this(bucket, pattern, String.Empty)
 {
 }
コード例 #11
0
ファイル: TripleSerializer.cs プロジェクト: giedomak/TripleT
 /// <summary>
 /// Writes the given triple to the given binary output stream, not writing the atom in the
 /// mini-bucket position.
 /// </summary>
 /// <param name="output">The output stream.</param>
 /// <param name="triple">The triple.</param>
 /// <param name="miniBucket">The mini-bucket position.</param>
 public static void Write(BinaryWriter output, Triple <Atom, Atom, Atom> triple, TriplePosition miniBucket)
 {
     if (miniBucket != TriplePosition.S)
     {
         output.Write(triple.S.InternalValue);
     }
     if (miniBucket != TriplePosition.P)
     {
         output.Write(triple.P.InternalValue);
     }
     if (miniBucket != TriplePosition.O)
     {
         output.Write(triple.O.InternalValue);
     }
 }
コード例 #12
0
ファイル: QueryPlan.cs プロジェクト: giedomak/TripleT
        /// <summary>
        /// Gets a descriptive scan operator for the given bucket, SAP, and optional starting atom.
        /// </summary>
        /// <param name="bucket">The bucket.</param>
        /// <param name="s">The s value (variable).</param>
        /// <param name="p">The p value (variable).</param>
        /// <param name="o">The o value (variable).</param>
        /// <param name="startAtom">The starting atom.</param>
        /// <returns>
        /// A descriptive scan operator for the given bucket, SAP, and starting atom.
        /// </returns>
        public static Scan GetScan(TriplePosition bucket, long s, long p, long o, string startAtom = "")
        {
            var pattern = new Pattern(s, p, o);

            return(new Scan(bucket, pattern, startAtom));
        }
コード例 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TripleComparer"/> class.
 /// </summary>
 /// <param name="primary">The primary comparison position.</param>
 /// <param name="secondary">The secondary comparison position.</param>
 /// <param name="tertiary">The tertiary comparison position.</param>
 public TripleComparer(TriplePosition primary, TriplePosition secondary, TriplePosition tertiary)
 {
     m_primary   = primary;
     m_secondary = secondary;
     m_tertiary  = tertiary;
 }