001package algs52; 002import stdlib.*; 003 004public class XTrieTimer { 005 public static void main(String[] args) { 006 //final String buildFilename = "data/shells.txt"; 007 //final String buildFilename = "data/leipzig1M.txt"; 008 String buildFilename = "data/mobydick.txt"; 009 010 //final String searchFilename = buildFilename; 011 //final String searchFilename = "data/mobydick.txt"; 012 String searchFilename = "data/leipzig1M.txt"; 013 014 //final RedBlackBST<String,Object> st = new RedBlackBST<>(); 015 //final SeparateChainingHashST<String,Object> st = new SeparateChainingHashST<>(); 016 TST<Object> st = new TST<>(); 017 //final LinearProbingHashST<String,Object> st = new LinearProbingHashST<>(); 018 019 // read in strings and add to set 020 Object nullObject = new Object(); 021 In buildFile = new In (buildFilename); 022 Stopwatch buildTimer = new Stopwatch(); 023 while (!buildFile.isEmpty()) { 024 String key = buildFile.readString(); 025 if (!st.contains(key)) { 026 st.put(key, nullObject); 027 //StdOut.println(key); 028 } 029 } 030 StdOut.format ("build time: %8.5f\n", buildTimer.elapsedTime ()); 031 032 // read in strings and check membership 033 In searchFile = new In (searchFilename); 034 Stopwatch searchTimer = new Stopwatch(); 035 int hits = 0; 036 int misses = 0; 037 while (!searchFile.isEmpty()) { 038 String key = searchFile.readString(); 039 if (st.contains(key)) hits++; 040 else misses++; 041 } 042 StdOut.format ("search time: %8.5f\n", searchTimer.elapsedTime ()); 043 StdOut.format ("hits: %13d\n", hits); 044 StdOut.format ("misses: %13d\n", misses); 045 } 046}