/// <summary> /// 保存置换表项 /// </summary> /// <param name="flag"></param> /// <param name="value"></param> /// <param name="depth"></param> /// <param name="mv"></param> public void RecordHash(int flag, int value, int depth, int mv) { HashItem hsh = hashTable[situation.Zobr.Key & (HASH_SIZE - 1)]; if (hsh.Depth > depth) { return; } hsh.Flag = flag; hsh.Depth = depth; if (value > ChessLogic.WIN_VALUE) { hsh.MvValue = value + situation.Distance; } else if (value < -ChessLogic.WIN_VALUE) { hsh.MvValue = value - situation.Distance; } else { hsh.MvValue = value; } hsh.Mv = mv; hsh.Lock0 = situation.Zobr.Lock0; hsh.Lock1 = situation.Zobr.Lock1; hashTable[situation.Zobr.Key & (HASH_SIZE - 1)] = hsh; }
public HashItem ed2kHash(HashItem item) { hasher.Clear(); FileInfo file = new FileInfo(item.Path); using (FileStream fs = file.OpenRead()) { AppendDebugLine("Hashing " + item.Name); byte[] temp; if ((temp = hasher.ComputeHash(fs)) != null) { item.Hash = string.Concat(temp.Select(b => b.ToString("x2")).ToArray()); AppendDebugLine("Ed2k hash: " + item.Hash); return(item); } else { AppendDebugLine("Hashing aborted"); } return(null); } }
public override void Delete(K kulcs) { HashItem p = A[h(kulcs)]; HashItem e = null; while (p != null && !p.key.Equals(kulcs)) { e = p; p = p.next; } if (p != null) { if (e == null) { A[h(kulcs)] = p.next; } else { e.next = p.next; } } else { throw new NoSuchKeyHashingException("No such key exists."); } }
public void MyListAdd(HashItem item) { Action addToList = new Action(delegate { string r_msg = String.Empty; APIResponse response = Execute(String.Format("MYLISTADD size={0}&ed2k={1}&viewed={2}&state={3}&edit={4}", item.Size, item.Hash, Convert.ToInt32(item.Watched), item.State, Convert.ToInt32(item.Edit))); switch (response.Code) { case RETURN_CODE.MYLIST_ENTRY_ADDED: File(item); r_msg = String.Format("Added {0} to mylist", item.Name); break; case RETURN_CODE.MYLIST_ENTRY_EDITED: File(item); r_msg = String.Format("Edited mylist entry for {0}", item.Name); break; case RETURN_CODE.FILE_ALREADY_IN_MYLIST: // TODO: add auto edit to options. item.Edit = true; MyListAdd(item); return; case RETURN_CODE.NO_SUCH_FILE: r_msg = "Error! File not in database"; break; } AppendDebugLine(r_msg); }); PrioritizedCommand(addToList); }
private void Grow() { var newSize = _table.Length << 1; var newTable = new HashItem[newSize]; _table.CopyTo(newTable, 0); _table = newTable; }
public HashTableWithOpenAddressing(int m) : base(m) { A = new HashItem[m]; for (int i = 0; i < m; i++) { A[i] = new HashItem(); } }
/// <summary> /// 初始化置换表 /// </summary> private void InitHashTable() { //清空置换表 System.Array.Clear(hashTable, 0, HASH_SIZE); for (int i = 0; i < HASH_SIZE; i++) { hashTable[i] = new HashItem(); } }
private async void PopulateHashItem(HashItem item, AutoResetEvent eventReset) { FileReport fileReport = null; fileReport = await GetFileReportAsyncWithRetries(item.ItemName, 100); item._dateTime = fileReport.ScanDate; item.PositiveDetections = fileReport.Scans?.Where(x => x.Value.Detected == true).Select(x => x.ToDetectionDTOMap()).ToList(); eventReset.Set(); }
private void OnFileWatched(object sender, FileWatchedArgs e) { HashItem item = e.Item; item.State = 1; item.Watched = item.FromMPC = true; lock (m_hashingLock) addRowToHashTable(item); }
public override void Insert(K key, T value) { HashItem newItem = new HashItem(); newItem.key = key; newItem.value = value; newItem.next = A[h(key)]; A[h(key)] = newItem; }
/// <summary> /// Used for an entry that is to be inserted into the database /// from a recently hashed HashItem. /// </summary> public FileEntry(HashItem item) { ed2k = item.Hash; size = item.Size; if (item.State == 1) path = item.Path; watched = item.Watched; generic = false; }
public void Add(object val) { int key = Hash(val); if (Data[key] == null) Data[key] = new HashItem(val); else { HashItem Cur = new HashItem(val); Cur.Next = Data[key]; Data[key] = Cur; } }
/// <summary> /// Adds a hashItem to the hash list. /// </summary> /// <param name="path">Path to file.</param> private void addRowToHashTable(HashItem item) { hashFileList.Insert(0, item); if (isHashing) { totalQueueSize += item.Size; } else if (!isHashing) { beginHashing(); } }
public void File(HashItem item) { Action fileInfo = new Action(delegate { APIResponse response = Execute(String.Format("FILE size={0}&ed2k={1}&fmask=78006A28B0&amask=F0E0F0C0", item.Size, item.Hash)); if (response.Code == RETURN_CODE.FILE) { ParseFileData(item, response.Message); } }); PrioritizedCommand(fileInfo); }
/// <summary> /// Creates a entry and adds it to the hash list. /// </summary> /// <param name="path">Path to file.</param> private void addRowToHashTable(string path) { HashItem item = new HashItem(path); hashFileList.Add(item); if (isHashing) { totalQueueSize += item.Size; } else if (!isHashing) { Dispatcher.BeginInvoke(new Action(delegate { hashingStartButton.IsEnabled = true; })); } }
// // Workshop methodes // virtual public bool Add(NAW naw) { /*-Als deze plek al bezet is ga je via linear probing op zoek naar de eerstvolgende * geschikte index. * -De methode retourneert een boolean die aangeeft of het element geplaatst kon * worden. * -Het is toegestaan om meerdere NAW objecten met dezelfde naam (een dus key) * toe te voegen.*/ int newHash = naw.Naam.GetHashCode(); //Something something % modulo if (_array == null) { _array = new Alg1HashItemArray(10); } int index = Math.Abs(newHash % Size); int originalIndex = index; HashItem newItem = new HashItem(naw.Naam, naw); bool inserted = false; while (!inserted) { if (_array.Size == _used) { break; } if (_array[index] == null || _array[index].IsDeleted) { _array[index] = newItem; _used++; inserted = true; } if (index >= _array.Size - 1) { index = 0; } else { index++; if (originalIndex == index) { break; } } } return(inserted); }
public override void Insert(K key, T value) { if (A[h(key)] != null) { // already in use A[h(key)].nextValues.Add(value); // end of the list } else { HashItem newItem = new HashItem(); newItem.key = key; newItem.value = value; newItem.nextValues = new List <T>(); A[h(key)] = newItem; } }
public override void Insert(K key, T value) { if (A[h(key)] != null) { // item already exists with this KEY A[h(key)].nextValues.Add(value); // add to end (!) of the list } else { // first item HashItem hi = new HashItem(); hi.key = key; hi.value = value; hi.nextValues = new List <T>(); A[h(key)] = hi; } }
public override T Search(K kulcs) { HashItem p = A[h(kulcs)]; while (p != null && !p.key.Equals(kulcs)) { p = p.next; } if (p != null) { return(p.value); } else { throw new NoSuchKeyHashingException("No such key exists."); } }
private void RecordHash(int depth, double value, int hashFlag, Decision decision) { Board board = chessBoard.BitBoard; if (hashTable.TryGetValue(board, out var hashItem)) { if (hashItem.depth > depth) { return; } } hashTable[board] = new HashItem() { value = value, hashFlag = hashFlag, depth = depth, decision = decision, }; }
public override void Delete(K key) { if (A[h(key)] == null) { throw new NoSuchKeyHashingException("No such key exists."); } else { HashItem x = A[h(key)]; if (x.nextValues.Count > 0) { x.nextValues.RemoveAt(x.nextValues.Count - 1); } else { A[h(key)] = null; } } }
public override T Search(K key) { if (A[h(key)] == null) { throw new NoSuchKeyHashingException("No such key exists."); } else { HashItem x = A[h(key)]; if (x.nextValues.Count > 0) { return(x.nextValues.Last()); } else { return(x.value); } } }
private void OnHashWorkerDoWork(object sender, DoWorkEventArgs e) { while (hashFileList.Count > 0 && isHashing) { if (m_HashWorker.CancellationPending) { e.Cancel = true; return; } HashItem thisItem = hashFileList[0], _temp = m_aniDBAPI.ed2kHash(thisItem); if (isHashing && _temp != null) // if we did not abort remove item from queue and process { Dispatcher.BeginInvoke(new Action <HashItem>(FinishHash), _temp); removeRowFromHashTable(hashFileList[hashFileList.IndexOf(thisItem)]); } } }
/// <summary> /// Adds completed hash item to mylist. /// </summary> private void FinishHash(HashItem item) { ppSize += item.Size; if (item.FromMPC) { m_aniDBAPI.MyListAdd(item); if (ConfigFile.Read("mpcShowOSD").ToBoolean() && m_mpcAPI != null && m_mpcAPI.isHooked) { m_mpcAPI.OSDShowMessage(String.Format("{0}: File marked as watched{1}", m_AppName, m_mpcAPI.CurrentFileName != item.Name ? String.Format(", ({0})", item.Name) : String.Empty)); } } else if (addToMyListCheckBox.IsChecked == true) { item.Watched = (bool)watchedCheckBox.IsChecked; item.State = stateComboBox.SelectedIndex; m_aniDBAPI.MyListAdd(item); } }
/// <summary> /// 提取置换表项 /// </summary> /// <param name="alpha"></param> /// <param name="beta"></param> /// <param name="depth"></param> /// <param name="mv"></param> /// <returns></returns> public int ProbeHash(int alpha, int beta, int depth, out int mv) { //杀棋标志:如果是杀棋,那么不需要满足深度条件 bool mate = false; HashItem hsh = hashTable[situation.Zobr.Key & (HASH_SIZE - 1)]; if (hsh.Lock0 != situation.Zobr.Lock0 || hsh.Lock1 != situation.Zobr.Lock1) { mv = 0; return(-ChessLogic.MATE_VALUE); } mv = hsh.Mv; if (hsh.MvValue > ChessLogic.WIN_VALUE) { hsh.MvValue -= situation.Distance; mate = true; } else if (hsh.MvValue < -ChessLogic.WIN_VALUE) { hsh.MvValue += situation.Distance; mate = true; } if (hsh.Depth > depth || mate) { if (hsh.Flag == HASH_BETA) { return(hsh.MvValue >= beta ? hsh.MvValue : -ChessLogic.MATE_VALUE); } else if (hsh.Flag == HASH_ALPHA) { return(hsh.MvValue <= alpha ? hsh.MvValue : -ChessLogic.MATE_VALUE); } return(hsh.MvValue); } return(-ChessLogic.MATE_VALUE); }
/// <summary> /// Removes a hash entry from the list. /// </summary> /// <param name="item">Item to remove.</param> /// <param name="userRemoved">True if removed by user.</param> private void removeRowFromHashTable(HashItem item, bool userRemoved = false) { if (isHashing && userRemoved) { totalQueueSize -= item.Size; if (item == hashFileList[0]) { m_aniDBAPI.cancelHashing(); } } lock (m_hashingLock) hashFileList.Remove(item); Dispatcher.BeginInvoke(new Action(delegate { if (hashFileList.Count == 0) { hashingStartButton.IsEnabled = hashingStopButton.IsEnabled = false; } })); }
public void Add(TKey key, TValue value) { if (_table.Length == Count) { Grow(); } var hash = GetHash(key); var item = _table[hash]; var newItem = new HashItem(key, value); if (item == null) { _table[hash] = newItem; } else { var tempItem = item; while (tempItem != null) { if (tempItem.Key.Equals(newItem.Key)) { throw new InvalidOperationException($"An item with the same key has already been added: {newItem.Key}"); } if (tempItem.Next == null) { tempItem.Next = newItem; break; } tempItem = tempItem.Next; } } Count++; }
/// <summary> /// Adds completed hash item to mylist. /// </summary> private void FinishHash(HashItem item) { ppSize += item.Size; if (item.FromMPC) { m_aniDBAPI.MyListAdd(item); if (ConfigFile.Read("mpcShowOSD").ToBoolean() && m_mpcAPI != null && m_mpcAPI.isHooked) m_mpcAPI.OSDShowMessage(String.Format("{0}: File marked as watched{1}", m_AppName, m_mpcAPI.CurrentFileName != item.Name ? String.Format(", ({0})", item.Name) : String.Empty)); } else if (addToMyListCheckBox.IsChecked == true) { item.Watched = (bool)watchedCheckBox.IsChecked; item.State = stateComboBox.SelectedIndex; m_aniDBAPI.MyListAdd(item); } }
public void File(HashItem item) { Action fileInfo = new Action(delegate { APIResponse response = Execute(String.Format("FILE size={0}&ed2k={1}&fmask=78006A28B0&amask=F0E0F0C0", item.Size, item.Hash)); if (response.Code == RETURN_CODE.FILE) ParseFileData(item, response.Message); }); PrioritizedCommand(fileInfo); }
/// <summary> /// Removes a hash entry from the list. /// </summary> /// <param name="item">Item to remove.</param> /// <param name="userRemoved">True if removed by user.</param> private void removeRowFromHashTable(HashItem item, bool userRemoved = false) { if (isHashing && userRemoved) { totalQueueSize -= item.Size; if (item == hashFileList[0]) m_aniDBAPI.cancelHashing(); } lock (m_hashingLock) hashFileList.Remove(item); Dispatcher.BeginInvoke(new Action(delegate { if (hashFileList.Count == 0) hashingStartButton.IsEnabled = hashingStopButton.IsEnabled = false; })); }
public static int CreateDelta(Snapshot from, Snapshot to, int[] outputData) { var numDeletedItems = 0; var numUpdatedItems = 0; var numTempItems = 0; var outputOffset = 3; var hashItems = new HashItem[HASHLIST_SIZE]; for (var i = 0; i < hashItems.Length; i++) { hashItems[i] = new HashItem(); } GenerateHash(hashItems, to); for (var i = 0; i < from.ItemsCount; i++) { var fromItem = from[i]; if (GetItemIndexHashed(fromItem.Key, hashItems) == -1) { numDeletedItems++; outputData[outputOffset++] = fromItem.Key; } } GenerateHash(hashItems, from); var pastIndecies = new int[SnapshotBuilder.MaxItems]; // fetch previous indices // we do this as a separate pass because it helps the cache for (var i = 0; i < to.ItemsCount; i++) { pastIndecies[i] = GetItemIndexHashed(to[i].Key, hashItems); } for (var i = 0; i < to.ItemsCount; i++) { var currentItem = to[i]; var itemSize = SnapshotItemsInfo.GetSize(currentItem.Item.GetType()); var pastIndex = pastIndecies[i]; if (pastIndex != -1) { var pastItem = from[pastIndex]; var offset = outputOffset + 3; if (itemSize != 0) { offset = outputOffset + 2; } if (DiffItem(pastItem.Item, currentItem.Item, outputData, offset) != 0) { outputData[outputOffset++] = (int)currentItem.Item.Type; outputData[outputOffset++] = currentItem.Id; if (itemSize == 0) { outputData[outputOffset++] = itemSize / sizeof(int); } outputOffset += itemSize / sizeof(int); // count item int fields numUpdatedItems++; } } else { outputData[outputOffset++] = (int)currentItem.Item.Type; outputData[outputOffset++] = currentItem.Id; if (itemSize == 0) { outputData[outputOffset++] = itemSize / sizeof(int); } var data = currentItem.Item.ToArray(); var output = outputData.AsSpan(outputOffset, data.Length); data.CopyTo(output); outputOffset += data.Length; numUpdatedItems++; } } if (numDeletedItems == 0 && numUpdatedItems == 0 && numTempItems == 0) { return(0); } outputData[0] = numDeletedItems; outputData[1] = numUpdatedItems; outputData[2] = numTempItems; return(outputOffset); }
public FileWatchedArgs(string f_Path) { Item = new HashItem(f_Path); }
/// <summary> /// Adds a hashItem to the hash list. /// </summary> /// <param name="path">Path to file.</param> private void addRowToHashTable(HashItem item) { hashFileList.Insert(0, item); if (isHashing) totalQueueSize += item.Size; else if (!isHashing) beginHashing(); }
public static int CreateDelta(Snapshot from, Snapshot to, int[] outputData) { var numDeletedItems = 0; var numUpdatedItems = 0; var numTempItems = 0; var outputOffset = 3; var hashItems = new HashItem[HASHLIST_SIZE]; for (var i = 0; i < hashItems.Length; i++) { hashItems[i] = new HashItem(); } GenerateHash(hashItems, to); // pack deleted stuff for (var i = 0; i < from.ItemsCount; i++) { var fromItem = from[i]; if (GetItemIndexHashed(fromItem.Key, hashItems) == -1) { // deleted numDeletedItems++; outputData[outputOffset++] = fromItem.Key; } } GenerateHash(hashItems, from); var pastIndecies = new int[SnapshotBuilder.MAX_SNAPSHOT_ITEMS]; // fetch previous indices // we do this as a separate pass because it helps the cache for (var i = 0; i < to.ItemsCount; i++) { pastIndecies[i] = GetItemIndexHashed(to[i].Key, hashItems); } for (var i = 0; i < to.ItemsCount; i++) { var currentItem = to[i]; var pastIndex = pastIndecies[i]; if (pastIndex != -1) { var pastItem = from[pastIndex]; var offset = outputOffset + 3; if (SnapObjectsInfo.GetSizeByType(currentItem.Type) != 0) { offset = outputOffset + 2; } if (DiffItem(pastItem.Object, currentItem.Object, outputData, offset) != 0) { outputData[outputOffset++] = (int)currentItem.Type; outputData[outputOffset++] = currentItem.Id; if (SnapObjectsInfo.GetSizeByType(currentItem.Type) == 0) { outputData[outputOffset++] = currentItem.Object.SerializeLength; } outputOffset += currentItem.Object.SerializeLength; // count item int fields numUpdatedItems++; } } else { outputData[outputOffset++] = (int)currentItem.Type; outputData[outputOffset++] = currentItem.Id; if (SnapObjectsInfo.GetSizeByType(currentItem.Type) == 0) { outputData[outputOffset++] = currentItem.Object.SerializeLength; } var data = currentItem.Object.Serialize(); Array.Copy(data, 0, outputData, outputOffset, data.Length); outputOffset += data.Length; numUpdatedItems++; } } if (numDeletedItems == 0 && numUpdatedItems == 0 && numTempItems == 0) { return(0); } outputData[0] = numDeletedItems; outputData[1] = numUpdatedItems; outputData[2] = numTempItems; return(outputOffset); }
public HashItem ed2kHash(HashItem item) { hasher.Clear(); FileInfo file = new FileInfo(item.Path); using (FileStream fs = file.OpenRead()) { AppendDebugLine("Hashing " + item.Name); byte[] temp; if ((temp = hasher.ComputeHash(fs)) != null) { item.Hash = string.Concat(temp.Select(b => b.ToString("x2")).ToArray()); AppendDebugLine("Ed2k hash: " + item.Hash); return item; } else AppendDebugLine("Hashing aborted"); return null; } }
/// <summary> /// Creates a entry and adds it to the hash list. /// </summary> /// <param name="path">Path to file.</param> private void addRowToHashTable(string path) { HashItem item = new HashItem(path); hashFileList.Add(item); if (isHashing) totalQueueSize += item.Size; else if (!isHashing) Dispatcher.BeginInvoke(new Action(delegate { hashingStartButton.IsEnabled = true; })); }