コード例 #1
0
        /// <summary>
        /// Finds all rows owned by <paramref name="key"/> in table <paramref name="tableSource"/>
        /// whose index is <paramref name="keyColIndex"/>
        /// </summary>
        /// <param name="tableSource">Table to search</param>
        /// <param name="keyColIndex">Key column index</param>
        /// <param name="key">Key</param>
        /// <returns>A <see cref="RidList"/> instance</returns>
        protected RidList FindAllRows(MDTable tableSource, int keyColIndex, uint key)
        {
            uint startRid = BinarySearch(tableSource, keyColIndex, key);

            if (tableSource.IsInvalidRID(startRid))
            {
                return(RidList.Empty);
            }
            uint endRid = startRid + 1;
            var  column = tableSource.TableInfo.Columns[keyColIndex];

            for (; startRid > 1; startRid--)
            {
                if (!tablesStream.TryReadColumn24(tableSource, startRid - 1, column, out uint key2))
                {
                    break;                      // Should never happen since startRid is valid
                }
                if (key != key2)
                {
                    break;
                }
            }
            for (; endRid <= tableSource.Rows; endRid++)
            {
                if (!tablesStream.TryReadColumn24(tableSource, endRid, column, out uint key2))
                {
                    break;                      // Should never happen since endRid is valid
                }
                if (key != key2)
                {
                    break;
                }
            }
            return(RidList.Create(startRid, endRid - startRid));
        }