예제 #1
0
파일: Trie.cs 프로젝트: shibox/JShibo.NLP
        /**
         * 建立failure表
         */
        private void constructFailureStates()
        {
            Queue <State> queue = new LinkedBlockingDeque <State>();

            // 第一步,将深度为1的节点的failure设为根节点
            for (State depthOneState : this.rootState.getStates())
            {
                depthOneState.setFailure(this.rootState);
                queue.add(depthOneState);
            }
            this.failureStatesConstructed = true;

            // 第二步,为深度 > 1 的节点建立failure表,这是一个bfs
            while (!queue.isEmpty())
            {
                State currentState = queue.remove();

                for (Character transition : currentState.getTransitions())
                {
                    State targetState = currentState.nextState(transition);
                    queue.add(targetState);

                    State traceFailureState = currentState.failure();
                    while (traceFailureState.nextState(transition) == null)
                    {
                        traceFailureState = traceFailureState.failure();
                    }
                    State newFailureState = traceFailureState.nextState(transition);
                    targetState.setFailure(newFailureState);
                    targetState.addEmit(newFailureState.emit());
                }
            }
        }
예제 #2
0
		//    Disambiguate from org.mozilla.javascript.Node
		/// <exception cref="System.IO.IOException"></exception>
		/// <exception cref="System.TypeLoadException"></exception>
		private void ReadObject(ObjectInputStream stream)
		{
			stream.DefaultReadObject();
			this.dom = DocumentBuilderFactory.NewInstance();
			this.dom.SetNamespaceAware(true);
			this.dom.SetIgnoringComments(false);
			this.xform = TransformerFactory.NewInstance();
			int poolSize = Runtime.GetRuntime().AvailableProcessors() * 2;
			this.documentBuilderPool = new LinkedBlockingDeque<DocumentBuilder>(poolSize);
		}
 private LinkedBlockingDeque<String> PopulatedDeque(int n)
 {
     LinkedBlockingDeque<String> q = new LinkedBlockingDeque<String>(n);
     Assert.IsTrue(q.IsEmpty());
     for(int i = 0; i < n; i++)
     {
         Assert.IsTrue(q.Offer(i.ToString()));
     }
     Assert.IsFalse(q.IsEmpty());
     Assert.AreEqual(0, q.RemainingCapacity());
     Assert.AreEqual(n, q.Size());
     return q;
 }
예제 #4
0
        public bool EndEvictionTest(LinkedBlockingDeque <PooledObject <T> > idleQueue)
        {
            lock (this.syncRoot)
            {
                if (state == PooledObjectState.MAINTAIN_EVICTION)
                {
                    state = PooledObjectState.IDLE;
                    return(true);
                }
                else if (state == PooledObjectState.MAINTAIN_EVICTION_RETURN_TO_HEAD)
                {
                    state = PooledObjectState.IDLE;
                    idleQueue.OfferFirst(this);
                }
            }

            return(false);
        }
예제 #5
0
        /// <exception cref="System.Exception"/>
        public virtual void TestMultiThreadedCompressorPool()
        {
            int             iterations             = 4;
            ExecutorService threadpool             = Executors.NewFixedThreadPool(3);
            LinkedBlockingDeque <Compressor> queue = new LinkedBlockingDeque <Compressor>(2 * iterations
                                                                                          );
            Callable <bool> consumer = new _Callable_110(queue);
            Callable <bool> producer = new _Callable_119(this, queue);

            for (int i = 0; i < iterations; i++)
            {
                threadpool.Submit(consumer);
                threadpool.Submit(producer);
            }
            // wait for completion
            threadpool.Shutdown();
            threadpool.AwaitTermination(1000, TimeUnit.Seconds);
            Assert.Equal(LeaseCountErr, 0, CodecPool.GetLeasedCompressorsCount
                             (codec));
        }
        public void TestAddAll5()
        {
            ArrayList<String> empty = new ArrayList<String>();
            ArrayList<String> strings = new ArrayList<String>(SIZE);

            for (int i = 0; i < SIZE; ++i)
            {
                strings.Add(i.ToString());
            }
            LinkedBlockingDeque<String> q = new LinkedBlockingDeque<String>(SIZE);
            Assert.IsFalse(q.AddAll(empty));
            Assert.IsTrue(q.AddAll(strings));
            for (int i = 0; i < SIZE; ++i)
            {
                Assert.AreEqual(strings.Get(i), q.Poll());
            }
        }
예제 #7
0
 public _Callable_147(LinkedBlockingDeque <Decompressor> queue)
 {
     this.queue = queue;
 }
예제 #8
0
 public _Callable_156(TestCodecPool _enclosing, LinkedBlockingDeque <Decompressor>
                      queue)
 {
     this._enclosing = _enclosing;
     this.queue      = queue;
 }
 public void TestOffer()
 {
     LinkedBlockingDeque<String> q = new LinkedBlockingDeque<String>(1);
     Assert.IsTrue(q.Offer(zero));
     Assert.IsFalse(q.Offer(one));
 }
예제 #10
0
 public _Callable_110(LinkedBlockingDeque <Compressor> queue)
 {
     this.queue = queue;
 }
 public void TestPut()
 {
     try
     {
         LinkedBlockingDeque<String> q = new LinkedBlockingDeque<String>(SIZE);
         for (int i = 0; i < SIZE; ++i)
         {
              q.Put(i.ToString());
              Assert.IsTrue(q.Contains(i.ToString()));
          }
          Assert.AreEqual(0, q.RemainingCapacity());
     }
     catch (Exception)
     {
         UnexpectedException();
     }
 }
 public void TestConstructor6()
 {
     ArrayList<String> strings = new ArrayList<String>();
     for (int i = 0; i < SIZE; ++i)
     {
         strings.Add(i.ToString());
     }
     LinkedBlockingDeque<String> q = new LinkedBlockingDeque<String>(strings);
     for (int i = 0; i < SIZE; ++i)
     {
         Assert.AreEqual(strings.Get(i), q.Poll());
     }
 }
예제 #13
0
		internal XmlProcessor()
		{
			SetDefault();
			this.dom = DocumentBuilderFactory.NewInstance();
			this.dom.SetNamespaceAware(true);
			this.dom.SetIgnoringComments(false);
			this.xform = TransformerFactory.NewInstance();
			int poolSize = Runtime.GetRuntime().AvailableProcessors() * 2;
			this.documentBuilderPool = new LinkedBlockingDeque<DocumentBuilder>(poolSize);
		}
 public void TestOfferNull()
 {
     try
     {
         LinkedBlockingDeque<String> q = new LinkedBlockingDeque<String>();
         q.Offer(null);
         ShouldThrow();
     }
     catch (NullReferenceException) {}
 }
 public void TestAddAll4()
 {
     try
     {
         LinkedBlockingDeque<String> q = new LinkedBlockingDeque<String>(1);
         ArrayList<String> strings = new ArrayList<String>();
         for (int i = 0; i < SIZE-1; ++i)
         {
             strings.Add(i.ToString());
         }
         q.AddAll(strings);
         ShouldThrow();
     }
     catch (IllegalStateException) {}
 }
 public void TestAdd()
 {
     try
     {
         LinkedBlockingDeque<String> q = new LinkedBlockingDeque<String>(SIZE);
         for (int i = 0; i < SIZE; ++i)
         {
             Assert.IsTrue(q.Add(i.ToString()));
         }
         Assert.AreEqual(0, q.RemainingCapacity());
         q.Add(SIZE.ToString());
     }
     catch (IllegalStateException)
     {
     }
 }
 public void TestAddAll3()
 {
     try
     {
         LinkedBlockingDeque<String> q = new LinkedBlockingDeque<String>(SIZE);
         ArrayList<String> strings = new ArrayList<String>();
         for (int i = 0; i < SIZE-1; ++i)
         {
             strings.Add(i.ToString());
         }
         strings.Add(null);
         q.AddAll(strings);
         ShouldThrow();
     }
     catch (NullReferenceException) {}
 }
 public void TestAddAll2()
 {
     try
     {
         LinkedBlockingDeque<String> q = new LinkedBlockingDeque<String>(SIZE);
         ArrayList<String> strings = new ArrayList<String>();
         strings.Add(null);
         strings.Add(null);
         strings.Add(null);
         q.AddAll(strings);
         ShouldThrow();
     }
     catch (NullReferenceException) {}
 }
 public void TestAddAll1()
 {
     try
     {
         LinkedBlockingDeque<String> q = new LinkedBlockingDeque<String>(1);
         q.AddAll(null);
         ShouldThrow();
     }
     catch (NullReferenceException) {}
 }
 public void TestPutNull()
 {
     try
     {
         LinkedBlockingDeque<String> q = new LinkedBlockingDeque<String>(SIZE);
         q.Put(null);
         ShouldThrow();
     }
     catch (NullReferenceException)
     {
     }
     catch (Exception)
     {
         UnexpectedException();
     }
 }
 public void TestEmptyFull()
 {
     LinkedBlockingDeque<String> q = new LinkedBlockingDeque<String>(2);
     Assert.IsTrue(q.IsEmpty());
     Assert.AreEqual(2, q.RemainingCapacity(), "should have room for 2");
     q.Add(one);
     Assert.IsFalse(q.IsEmpty());
     q.Add(two);
     Assert.IsFalse(q.IsEmpty());
     Assert.AreEqual(0, q.RemainingCapacity());
     Assert.IsFalse(q.Offer(three));
 }