Hash Table is a data structure which stores data in an associative manner. In a hash table, data is stored in an array format, where each data value has its own unique index value. Access of data becomes very fast if we know the index of the desired data.
/** * @Auther: Arsenal * @Date: 2020-03-23 19:13 * @Description: 哈希表 */ publicclassHashTable{ publicstaticvoidmain(String[] args){ EmpHashTable empHashTable = new EmpHashTable(6); /*for (int i = 0; i < 10; i++) { Emp emp = new Emp(i, "老王" + i); empHashTable.addEmp(emp); } empHashTable.list(); System.out.println("============================="); //empHashTable.findEmpById(8); empHashTable.delEmpById(18); empHashTable.list();*/ /*for (int i = 30; i > 0; i--) { Emp emp = new Emp(i, "老王" + i); empHashTable.addEmpByOrder(emp); } empHashTable.list();*/
for (int i = 0; i < 20; i++) { int id = new Random().nextInt(40); Emp emp = new Emp(id, "老王" + i); //empHashTable.addEmp(emp); empHashTable.addEmpByOrder(emp); } empHashTable.list();
} }
/** * hash表 */ classEmpHashTable{ public EmpLinkedList[] empLinkedList; privateint size;
// 初始化hashTable publicEmpHashTable(int size){ this.size = size; this.empLinkedList = new EmpLinkedList[size]; // 初始化链表 for (int i = 0; i < size; i++) { empLinkedList[i] = new EmpLinkedList(); } }