/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections;
using System.Linq;
using System.Collections.Generic;
namespace Lucene.Net.Analysis
{
/// A simple class that stores Strings as char[]'s in a
/// hash table. Note that this is not a general purpose
/// class. For example, it cannot remove items from the
/// set, nor does it resize its hash table to be smaller,
/// etc. It is designed to be quick to test if a char[]
/// is in the set without the necessity of converting it
/// to a String first.
///
/// Please note: This class implements but
/// does not behave like it should in all cases. The generic type is
/// , because you can add any object to it,
/// that has a string representation. The add methods will use
/// and store the result using a
/// buffer. The same behaviour have the methods.
/// The method returns an IEnumerable.
/// For type safety also {@link #stringIterator()} is provided.
///
// TODO: java uses wildcards, .net doesn't have this, easiest way is to
// make the entire class generic. Ultimately, though, since this
// works with strings, I can't think of a reason not to just declare
// this as an ISet.
public class CharArraySet : ISet
{
bool _ReadOnly = false;
const int INIT_SIZE = 8;
char[][] _Entries;
int _Count;
bool _IgnoreCase;
public static CharArraySet EMPTY_SET = UnmodifiableSet(new CharArraySet(0, false));
private void Init(int startSize, bool ignoreCase)
{
this._IgnoreCase = ignoreCase;
int size = INIT_SIZE;
while (startSize + (startSize >> 2) > size)
size <<= 1;
_Entries = new char[size][];
}
/// Create set with enough capacity to hold startSize
/// terms
///
public CharArraySet(int startSize, bool ignoreCase)
{
Init(startSize, ignoreCase);
}
public CharArraySet(IEnumerable c, bool ignoreCase)
{
Init(c.Count(), ignoreCase);
AddItems(c);
}
/// Create set from a Collection of char[] or String
public CharArraySet(IEnumerable