Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since JavaScript numbers can hold integers of over 50 bits, 3 numbers could keep track of 150 files. </p> <p>The following code provides functions for creating, manipulating and interrogating a data structure consisting of an array of 50 bit numbers:</p> <pre><code>function Set (len) { // Establish an array of sufficient 50 bit numbers to hold len bits this.bits = new Array (Math.floor ((len + 49) / 50)); this.len = len; // Clear all numbers for (var i = this.bits.length; i--;) this.bits[i] = 0; } Set.prototype.full = function () { // Check if all bits of the set at 1 // First check the relevant bits of the last word if (this.bits[this.bits.length - 1] === Math.pow (2, this.len + 1) - 1) // Then chec tat all remaining numbers are full for (var i = this.bits.length - 1; i--;) if (bits[i] !== Math.pow (2, 51) - 1) return false; return true; } Set.prototype.check = function (n) { // Return value (0 or 1) of bit n of the set var m = n % 50; return Math.floor (this.bits [(n - m) / 50] / Math.pow (2, m)) &amp; 1; } Set.prototype.add = function (n) { // Set bit n of the set to 1 (unless it is already 1) if (!this.check (n)) { var m = n % 50; this.bits [(n - m) / 50] += Math.pow (2, m); return true; } return false; } Set.prototype.remove = function (n) { // Set bit of the set to 0 (unless it is already 0) if (this.check (n)) { var m = n % 50; this.bits [(n - m) / 50] -= Math.pow (2, m); return true; } return false; } Set.prototype.clear = function () { // Clear all bitsof the set to 0 for (var i = this.bits.length; i--;) bits[i] = 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload