⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bytevector.cs

📁 itextsharp for pdf document
💻 CS
字号:
using System;
using System.Collections;

/*
 * $Id: ByteVector.cs,v 1.1.1.1 2003/02/04 02:58:41 geraldhenson Exp $
 * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
 * For details on use and redistribution please refer to the
 * LICENSE file included with these sources.
 */

namespace iTextSharp.text.pdf.hyphenation {
	/**
	 * This class implements a simple byte vector with access to the
	 * underlying array.
	 *
	 * @author Carlos Villegas <cav@uniscope.co.jp>
	 */
	public class ByteVector {

		/**
		 * Capacity increment size
		 */
		private static int DEFAULT_BLOCK_SIZE = 2048;
		private int BLOCK_SIZE;

		/**
		 * The encapsulated array
		 */
		private byte[] arr;

		/**
		 * Points to next free item
		 */
		private int n;

		public ByteVector() : this(DEFAULT_BLOCK_SIZE) {}

		public ByteVector(int capacity) {
			if (capacity > 0)
				BLOCK_SIZE = capacity;
			else
				BLOCK_SIZE = DEFAULT_BLOCK_SIZE;
			arr = new byte[BLOCK_SIZE];
			n = 0;
		}

		public ByteVector(byte[] a) {
			BLOCK_SIZE = DEFAULT_BLOCK_SIZE;
			arr = a;
			n = 0;
		}

		public ByteVector(byte[] a, int capacity) {
			if (capacity > 0)
				BLOCK_SIZE = capacity;
			else
				BLOCK_SIZE = DEFAULT_BLOCK_SIZE;
			arr = a;
			n = 0;
		}

		public byte[] Arr {
			get {
				return arr;
			}
		}

		/**
		 * return number of items in array
		 */
		public int Length {
			get {
				return n;
			}
		}

		/**
		 * returns current capacity of array
		 */
		public int Capacity {
			get {
				return arr.Length;
			}
		}

		public byte this[int index] {
			get {
				return arr[index];
			}

			set {
				arr[index] = value;
			}
		}

		/**
		 * This is to implement memory allocation in the array. Like malloc().
		 */
		public int alloc(int size) {
			int index = n;
			int len = arr.Length;
			if (n + size >= len) {
				byte[] aux = new byte[len + BLOCK_SIZE];
				Array.Copy(arr, 0, aux, 0, len);
				arr = aux;
			}
			n += size;
			return index;
		}

		public void trimToSize() {
			if (n < arr.Length) {
				byte[] aux = new byte[n];
				Array.Copy(arr, 0, aux, 0, n);
				arr = aux;
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -