public virtual void AddTerm(Term term, int docIDUpto) { terms.TryGetValue(term, out int?current); if (current != null && docIDUpto < current) { // Only record the new number if it's greater than the // current one. this is important because if multiple // threads are replacing the same doc at nearly the // same time, it's possible that one thread that got a // higher docID is scheduled before the other // threads. If we blindly replace than we can // incorrectly get both docs indexed. return; } terms[term] = docIDUpto; // note that if current != null then it means there's already a buffered // delete on that term, therefore we seem to over-count. this over-counting // is done to respect IndexWriterConfig.setMaxBufferedDeleteTerms. numTermDeletes.IncrementAndGet(); if (current == null) { bytesUsed.AddAndGet(BYTES_PER_DEL_TERM + term.Bytes.Length + (RamUsageEstimator.NUM_BYTES_CHAR * term.Field.Length)); } }
public virtual void AddBinaryUpdate(BinaryDocValuesUpdate update, int docIDUpto) { if (!binaryUpdates.TryGetValue(update.field, out LinkedDictionary <Term, BinaryDocValuesUpdate> fieldUpdates)) { fieldUpdates = new LinkedDictionary <Term, BinaryDocValuesUpdate>(); binaryUpdates[update.field] = fieldUpdates; bytesUsed.AddAndGet(BYTES_PER_BINARY_FIELD_ENTRY); } if (fieldUpdates.TryGetValue(update.term, out BinaryDocValuesUpdate current) && current != null && docIDUpto < current.docIDUpto) { // Only record the new number if it's greater than or equal to the current // one. this is important because if multiple threads are replacing the // same doc at nearly the same time, it's possible that one thread that // got a higher docID is scheduled before the other threads. return; } update.docIDUpto = docIDUpto; // since it's an LinkedHashMap, we must first remove the Term entry so that // it's added last (we're interested in insertion-order). if (current != null) { fieldUpdates.Remove(update.term); } fieldUpdates[update.term] = update; numBinaryUpdates.IncrementAndGet(); if (current == null) { bytesUsed.AddAndGet(BYTES_PER_BINARY_UPDATE_ENTRY + update.GetSizeInBytes()); } }
internal virtual void AddNumericUpdate(NumericDocValuesUpdate update, int docIDUpto) // LUCENENET specific - Made internal rather than public, since this class is intended to be internal but couldn't be because it is exposed through a public API { if (!numericUpdates.TryGetValue(update.field, out LinkedDictionary <Term, NumericDocValuesUpdate> fieldUpdates)) { fieldUpdates = new LinkedDictionary <Term, NumericDocValuesUpdate>(); numericUpdates[update.field] = fieldUpdates; bytesUsed.AddAndGet(BYTES_PER_NUMERIC_FIELD_ENTRY); } if (fieldUpdates.TryGetValue(update.term, out NumericDocValuesUpdate current) && current != null && docIDUpto < current.docIDUpto) { // Only record the new number if it's greater than or equal to the current // one. this is important because if multiple threads are replacing the // same doc at nearly the same time, it's possible that one thread that // got a higher docID is scheduled before the other threads. return; } update.docIDUpto = docIDUpto; // since it's an LinkedHashMap, we must first remove the Term entry so that // it's added last (we're interested in insertion-order). if (current != null) { fieldUpdates.Remove(update.term); } fieldUpdates[update.term] = update; numNumericUpdates.IncrementAndGet(); if (current is null) { bytesUsed.AddAndGet(BYTES_PER_NUMERIC_UPDATE_ENTRY + update.GetSizeInBytes()); } }
public virtual void AddQuery(Query query, int docIDUpto) { queries.TryGetValue(query, out int?prev); queries[query] = docIDUpto; // increment bytes used only if the query wasn't added so far. if (prev == null) { bytesUsed.AddAndGet(BYTES_PER_DEL_QUERY); } }
public static TValue GetOrDefault <TKey, TValue>(this SCG.IDictionary <TKey, TValue> dictionary, TKey key, TValue defaultValue = default(TValue)) { TValue value; if (!dictionary.TryGetValue(key, out value)) { value = defaultValue; } return(value); }
public static TValue GetOrAdd <TKey, TValue>(this SCG.IDictionary <TKey, TValue> dictionary, TKey key, System.Func <TKey, TValue> defaultFactory) { TValue value; if (!dictionary.TryGetValue(key, out value)) { dictionary.Add(key, value = defaultFactory(key)); } return(value); }
internal virtual void AddQuery(Query query, int docIDUpto) // LUCENENET specific - Made internal rather than public, since this class is intended to be internal but couldn't be because it is exposed through a public API { bool prevExists = queries.TryGetValue(query, out _); queries[query] = docIDUpto; // increment bytes used only if the query wasn't added so far. if (!prevExists) { bytesUsed.AddAndGet(BYTES_PER_DEL_QUERY); } }