public void ReadCosts(Stream input)
        {
            using (StreamReader reader = new StreamReader(input))
            {
                string   line          = reader.ReadLine();
                string[] cardinalities = line.SplitSpace();

                int forwardSize  = Int32.Parse(cardinalities[0]);
                int backwardSize = Int32.Parse(cardinalities[1]);

                cardinality = backwardSize;
                bufferSize  = forwardSize * backwardSize * Constant.SHORT_BYTES;

                if (costs != null)
                {
                    costs.Dispose();
                }

                costs = new MemoryStreamWrapper(new MemoryStream(bufferSize));

                while (!reader.EndOfStream)
                {
                    string[] fields = reader.ReadLine().SplitSpace();

                    short forwardId  = Int16.Parse(fields[0]);
                    short backwardId = Int16.Parse(fields[1]);
                    short cost       = Int16.Parse(fields[2]);

                    PutCost(forwardId, backwardId, cost);
                }
            }
        }
 public void Dispose()
 {
     if (buffer != null)
     {
         buffer.Dispose();
     }
 }
 public void Dispose()
 {
     if (costs != null)
     {
         costs.Dispose();
     }
 }
Exemple #4
0
        public TokenInfoBuffer(Stream inputStream)
        {
            try
            {
                if (buffer != null)
                {
                    buffer.Dispose();
                }

                buffer         = new MemoryStreamWrapper(ByteBufferIO.Read(inputStream));
                tokenInfoCount = GetTokenInfoCount();
                posInfoCount   = GetPosInfoCount();
                featureCount   = GetFeatureCount();
                entrySize      = GetEntrySize(tokenInfoCount, posInfoCount, featureCount);
            }
            catch (Exception ex)
            {
                throw new IOException("TokenInfoBuffer Constructor: " + ex.Message);
            }
        }
Exemple #5
0
        private void Put(SortedDictionary <int, string> strings)
        {
            int bufferSize = CalculateSize(strings);

            size = strings.Count;

            if (buffer != null)
            {
                buffer.Dispose();
            }

            buffer = new MemoryStreamWrapper(new MemoryStream(bufferSize));
            buffer.WriteInt32(size);                 // Set entries

            int keyIndex   = Constant.INTEGER_BYTES; // First key index is past size
            int entryIndex = keyIndex + size * Constant.INTEGER_BYTES;

            foreach (string str in strings.Values)
            {
                buffer.WriteInt32(entryIndex, keyIndex);
                entryIndex = Put(entryIndex, str);
                keyIndex  += Constant.INTEGER_BYTES;
            }
        }