Ejemplo n.º 1
0
            /// <summary>
            /// add a term </summary>
            public virtual void Add(Term term)
            {
                Debug.Assert(lastTerm.Equals(new Term("")) || term.CompareTo(lastTerm) > 0);

                try
                {
                    int prefix = SharedPrefix(lastTerm.Bytes, term.Bytes);
                    int suffix = term.Bytes.Length - prefix;
                    if (term.Field.Equals(lastTerm.Field, StringComparison.Ordinal))
                    {
                        output.WriteVInt32(prefix << 1);
                    }
                    else
                    {
                        output.WriteVInt32(prefix << 1 | 1);
                        output.WriteString(term.Field);
                    }
                    output.WriteVInt32(suffix);
                    output.WriteBytes(term.Bytes.Bytes, term.Bytes.Offset + prefix, suffix);
                    lastTerm.Bytes.CopyBytes(term.Bytes);
                    lastTerm.Field = term.Field;
                }
                catch (IOException e)
                {
                    throw new Exception(e.ToString(), e);
                }
            }
Ejemplo n.º 2
0
            /// <summary>
            /// add a term </summary>
            public virtual void Add(Term term)
            {
                Debug.Assert(LastTerm.Equals(new Term("")) || term.CompareTo(LastTerm) > 0);

                try
                {
                    int prefix = SharedPrefix(LastTerm.Bytes_Renamed, term.Bytes_Renamed);
                    int suffix = term.Bytes_Renamed.Length - prefix;
                    if (term.Field_Renamed.Equals(LastTerm.Field_Renamed))
                    {
                        Output.WriteVInt(prefix << 1);
                    }
                    else
                    {
                        Output.WriteVInt(prefix << 1 | 1);
                        Output.WriteString(term.Field_Renamed);
                    }
                    Output.WriteVInt(suffix);
                    Output.WriteBytes(term.Bytes_Renamed.Bytes, term.Bytes_Renamed.Offset + prefix, suffix);
                    LastTerm.Bytes_Renamed.CopyBytes(term.Bytes_Renamed);
                    LastTerm.Field_Renamed = term.Field_Renamed;
                }
                catch (IOException e)
                {
                    throw new Exception(e.Message, e);
                }
            }