Example #1
0
 /// <summary>
 /// OBS this implementation can only provide values for properties of type <seealso cref="string"/>.
 /// Other property types will still be counted as distinct, but {@code client} won't receive <seealso cref="Value"/>
 /// instances for those. </summary>
 /// <param name="client"> <seealso cref="IndexProgressor.NodeValueClient"/> to get initialized with this progression. </param>
 /// <param name="propertyAccessor"> <seealso cref="NodePropertyAccessor"/> for reading property values. </param>
 /// <param name="needsValues"> whether or not to load string values. </param>
 public override void DistinctValues(Org.Neo4j.Storageengine.Api.schema.IndexProgressor_NodeValueClient client, NodePropertyAccessor propertyAccessor, bool needsValues)
 {
     try
     {
         IndexQuery[]            noQueries       = new IndexQuery[0];
         BridgingIndexProgressor multiProgressor = new BridgingIndexProgressor(client, _descriptor.schema().PropertyIds);
         Fields fields = MultiFields.getFields(IndexSearcher.IndexReader);
         foreach (ValueEncoding valueEncoding in ValueEncoding.values())
         {
             Terms terms = fields.terms(valueEncoding.key());
             if (terms != null)
             {
                 System.Func <BytesRef, Value> valueMaterializer = valueEncoding == ValueEncoding.String && needsValues ? term => Values.stringValue(term.utf8ToString()) : term => null;
                 TermsEnum termsIterator = terms.GetEnumerator();
                 if (valueEncoding == ValueEncoding.Number)
                 {
                     termsIterator = NumericUtils.filterPrefixCodedLongs(termsIterator);
                 }
                 multiProgressor.Initialize(_descriptor, new LuceneDistinctValuesProgressor(termsIterator, client, valueMaterializer), noQueries, IndexOrder.NONE, needsValues);
             }
         }
         client.Initialize(_descriptor, multiProgressor, noQueries, IndexOrder.NONE, needsValues);
     }
     catch (IOException e)
     {
         throw new UncheckedIOException(e);
     }
 }
Example #2
0
        protected bool Equals(Attachment other)
        {
            var firstPart = Equals(Uri, other.Uri) && ValueEncoding.Equals(other.ValueEncoding);

            return(Data == null
                ? firstPart
                : firstPart && Data.SequenceEqual(other.Data));
        }
Example #3
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Uri?.GetHashCode() ?? 0;
         hashCode = (hashCode * 397) ^ (CollectionHelpers.GetHashCode(Data));
         hashCode = (hashCode * 397) ^ (ValueEncoding?.GetHashCode() ?? 0);
         return(hashCode);
     }
 }
Example #4
0
 public override string?this[string option]
 {
     get
     {
         if (Protocol == Protocol.Ice1)
         {
             return(option switch
             {
                 "value" => Value.Length > 0 ? Convert.ToBase64String(Value.Span) : null,
                 "value-encoding" => ValueEncoding.ToString(),
                 _ => null,
             });
Example #5
0
            internal virtual Field GetFieldWithValue(int propertyNumber, Value value)
            {
                ValueEncoding encoding      = ValueEncoding.forValue(value);
                int           reuseId       = propertyNumber * ValueEncoding.values().length + encoding.ordinal();
                string        key           = encoding.key(propertyNumber);
                Field         reusableField = ReusableValueFields[reuseId];

                if (reusableField == null)
                {
                    reusableField = encoding.encodeField(key, value);
                    ReusableValueFields[reuseId] = reusableField;
                }
                else
                {
                    encoding.setFieldValue(value, reusableField);
                }
                return(reusableField);
            }
Example #6
0
 public override string ToString()
 {
     return(Data == null
         ? string.Empty
         : ValueEncoding.GetString(Data));
 }
Example #7
0
        private NetpbmHeader <TPixelFormat> ReadPGMOrPPMHeader <TPixelFormat>(Stream stream, ValueEncoding valueEncoding, IImageFactory <TPixelFormat> imageFactory, params Component[] components)
        {
            int width;
            var widthBytes  = SkipWhitespaceAndReadUntilNextWhitespaceByte(stream, true);
            var widthString = GetUsAsciiString(widthBytes);

            if (!TryParseIntInvariant(widthString, out width))
            {
                throw new InvalidDataException(string.Format("failed to parse width '{0}'", widthString));
            }

            int height;
            var heightBytes  = SkipWhitespaceAndReadUntilNextWhitespaceByte(stream, true);
            var heightString = GetUsAsciiString(heightBytes);

            if (!TryParseIntInvariant(heightString, out height))
            {
                throw new InvalidDataException(string.Format("failed to parse height '{0}'", heightString));
            }

            var          highestValueBytes  = SkipWhitespaceAndReadUntilNextWhitespaceByte(stream, true);
            var          highestValueString = GetUsAsciiString(highestValueBytes);
            TPixelFormat highestValue       = imageFactory.ParseHighestComponentValue(highestValueString);

            // final byte of whitespace has been discarded by SkipWhitespaceAndReadUntilNextWhitespaceByte

            return(new NetpbmHeader <TPixelFormat>(
                       (components.Length == 1)
                    ? ((valueEncoding == ValueEncoding.Binary) ? ImageType.PGM : ImageType.PlainPGM)
                    : ((valueEncoding == ValueEncoding.Binary) ? ImageType.PPM : ImageType.PlainPPM),
                       width,
                       height,
                       imageFactory.GetNumberOfBytesPerPixelComponent(highestValue),
                       components,
                       highestValue
                       ));

            //return imageFactory.MakeImage(width, height, highestValue, components, rows);
        }
Example #8
0
        private NetpbmHeader <TPixelFormat> ReadPBMHeader <TPixelFormat>(Stream stream, ValueEncoding valueEncoding, IImageFactory <TPixelFormat> imageFactory)
        {
            int width;
            var widthBytes  = SkipWhitespaceAndReadUntilNextWhitespaceByte(stream, true);
            var widthString = GetUsAsciiString(widthBytes);

            if (!TryParseIntInvariant(widthString, out width))
            {
                throw new InvalidDataException(string.Format("failed to parse width '{0}'", widthString));
            }

            int height;
            var heightBytes  = SkipWhitespaceAndReadUntilNextWhitespaceByte(stream, true);
            var heightString = GetUsAsciiString(heightBytes);

            if (!TryParseIntInvariant(heightString, out height))
            {
                throw new InvalidDataException(string.Format("failed to parse height '{0}'", heightString));
            }

            // final byte of whitespace has been discarded by SkipWhitespaceAndReadUntilNextWhitespaceByte

            return(new NetpbmHeader <TPixelFormat>(
                       (valueEncoding == ValueEncoding.Plain) ? ImageType.PlainPBM : ImageType.PBM,
                       width,
                       height,
                       1,
                       new[] { Component.Black },
                       imageFactory.BitmapOnPixelComponentValue
                       ));
        }