private GetDeviceIndex ( |
||
reader | Reader with exclusive access to the underlying file | |
userAgent | byte | A null terminated byte array of the User-Agent to be tested |
index | int | The index in the array of the current character |
parentDeviceIndex | int | The device index of the parent node |
return | int |
/// <summary> /// In a single thread loops through the useragents in the file /// provided perform a match with the data set provided passing /// control back to the method provided for further processing. /// </summary> /// <param name="provider"></param> /// <param name="userAgents"></param> /// <param name="method"></param> /// <returns>Counts for each of the methods used</returns> internal static Results DetectLoopSingleThreaded(TrieProvider provider, IEnumerable<string> userAgents, ProcessTrie method, object state) { var results = new Results(); foreach (var line in userAgents) { method(results, provider.GetDeviceIndex(line.Trim()), state); results.Count++; } ReportMethods(results.Methods); ReportTime(results); return results; }
/// <summary> /// Using multiple threads loops through the useragents in the file /// provided perform a match with the data set provided passing /// control back to the method provided for further processing. /// </summary> /// <param name="provider"></param> /// <param name="userAgents"></param> /// <param name="method"></param> /// <returns>Counts for each of the methods used</returns> internal static Results DetectLoopMultiThreaded(TrieProvider provider, IEnumerable<string> userAgents, ProcessTrie method, object state) { var results = new Results(); Parallel.ForEach(userAgents, line => { method(results, provider.GetDeviceIndex(line.Trim()), state); Interlocked.Increment(ref results.Count); }); ReportMethods(results.Methods); ReportTime(results); return results; }