public void Set(byte[] key, byte[] value) { BinaryKey binaryKey = new BinaryKey(key); BinaryRecord binaryRecord = new BinaryRecord(binaryKey, value); int index = KeyHasher.HashKey(binaryKey, BucketArraySize); BucketArray.Insert(binaryRecord, index); }
public void Set(string key, byte[] value) { StringKey stringKey = new StringKey(key); StringRecord stringRecord = new StringRecord(stringKey, value); int index = KeyHasher.HashKey(stringKey, BucketArraySize); BucketArray.Insert(stringRecord, index); }
public void Get(string key) { StringKey stringKey = new StringKey(key); Record record; int index = KeyHasher.HashKey(stringKey, BucketArraySize); try { record = BucketArray.Select(stringKey, index); BinaryResult = record.Value; } catch (NoValueException e) { Console.WriteLine(e.Message); } }
public List <IGroupCacheClient> PickPeers(string key, int numPeers) { lock (_lock) { numPeers = Math.Min(numPeers, _peerEndpoints.Count); List <IGroupCacheClient> replica = new List <IGroupCacheClient>(numPeers); List <PeerEndpoint> buckets = new List <PeerEndpoint>(_peerEndpoints); for (int i = 0; i < numPeers; i++) { var keyHash = KeyHasher.GetHashCode(key); var index = _consistentHasher.Hash((ulong)keyHash, buckets.Count); replica.Add(_clients[buckets[index]]); // Remove this node from buckets to guarantee its note added twice to replica list buckets.RemoveAt(index); } return(replica); } }
private Key GetKeyFromListboxValue() { if (KeysByGroupListbox.SelectedIndex < 0) { return(new Key()); } // Need to know the scancode and extended of the chosen key. string keyname = KeysByGroupListbox.Text; int hash; if (currentgroupmembers.ContainsKey(keyname)) { hash = currentgroupmembers[keyname]; } else { // As this is a lookup on an internal list we really should know what they are. return(new Key()); } return(new Key(KeyHasher.GetScancodeFromHash(hash), KeyHasher.GetExtendedFromHash(hash))); }
private void DrawRow(IEnumerable <KeyboardRow> Rows, int leftstart, int top) { int left = leftstart; // Need to set the exact width of the row. int width = (int)(14.7F * (keySize + paddingWidth)); if (width % 2 != 0) { width += 1; } foreach (var row in Rows) { foreach (var key in row.Keys) { if (key == null) { // Spacer - eg to centre the up arrow key left += (int)Math.Round((decimal)keySize, 0) + paddingWidth; } else { // The last key in the row must be stretched appropriately. // Which one's that, then? int index = Array.IndexOf(rowTerminators, KeyHasher.GetHashFromKeyData(key.ScanCode, key.Extended)); if (index < 0) { DrawKey(key.ScanCode, key.Extended, ref left, top, key.Button, key.HorizontalStretch * paddingWidth, key.VerticalStretch * paddingWidth); } else { // Ok. How much space is left to fill? // left is where we are to start drawing, width is the line width. int keywidth = width - left; // Calculate the horizontal stretch value based on the sizes: int buttonwidth = 0; switch (key.Button) { case BlankButton.Blank: case BlankButton.TallBlank: buttonwidth = 128; break; case BlankButton.MediumWideBlank: buttonwidth = 192; break; case BlankButton.DoubleWideBlank: buttonwidth = 256; break; case BlankButton.TripleWideBlank: buttonwidth = 384; break; case BlankButton.QuadrupleWideBlank: buttonwidth = 512; break; default: break; } int stretch = (int)(keywidth - (buttonwidth * buttonScale)); DrawKey(key.ScanCode, key.Extended, ref left, top, key.Button, stretch, key.VerticalStretch * paddingWidth); } left += key.RightPadding * paddingWidth; } } top += paddingWidth + (int)Math.Round((decimal)keySize, 0); left = leftstart; } }
public override int GetHashCode() { return(KeyHasher.GetHashFromKey(this)); }