mirror of
https://github.com/bvanroll/yahoo-thing.git
synced 2025-08-29 03:52:44 +00:00
euh
This commit is contained in:
4
node_modules/memory-pager/.travis.yml
generated
vendored
Normal file
4
node_modules/memory-pager/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- '4'
|
||||
- '6'
|
21
node_modules/memory-pager/LICENSE
generated
vendored
Normal file
21
node_modules/memory-pager/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 Mathias Buus
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
65
node_modules/memory-pager/README.md
generated
vendored
Normal file
65
node_modules/memory-pager/README.md
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
# memory-pager
|
||||
|
||||
Access memory using small fixed sized buffers instead of allocating a huge buffer.
|
||||
Useful if you are implementing sparse data structures (such as large bitfield).
|
||||
|
||||

|
||||
|
||||
```
|
||||
npm install memory-pager
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
``` js
|
||||
var pager = require('paged-memory')
|
||||
|
||||
var pages = pager(1024) // use 1kb per page
|
||||
|
||||
var page = pages.get(10) // get page #10
|
||||
|
||||
console.log(page.offset) // 10240
|
||||
console.log(page.buffer) // a blank 1kb buffer
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
#### `var pages = pager(pageSize)`
|
||||
|
||||
Create a new pager. `pageSize` defaults to `1024`.
|
||||
|
||||
#### `var page = pages.get(pageNumber, [noAllocate])`
|
||||
|
||||
Get a page. The page will be allocated at first access.
|
||||
|
||||
Optionally you can set the `noAllocate` flag which will make the
|
||||
method return undefined if no page has been allocated already
|
||||
|
||||
A page looks like this
|
||||
|
||||
``` js
|
||||
{
|
||||
offset: byteOffset,
|
||||
buffer: bufferWithPageSize
|
||||
}
|
||||
```
|
||||
|
||||
#### `pages.set(pageNumber, buffer)`
|
||||
|
||||
Explicitly set the buffer for a page.
|
||||
|
||||
#### `pages.updated(page)`
|
||||
|
||||
Mark a page as updated.
|
||||
|
||||
#### `pages.lastUpdate()`
|
||||
|
||||
Get the last page that was updated.
|
||||
|
||||
#### `var buf = pages.toBuffer()`
|
||||
|
||||
Concat all pages allocated pages into a single buffer
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
160
node_modules/memory-pager/index.js
generated
vendored
Normal file
160
node_modules/memory-pager/index.js
generated
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
module.exports = Pager
|
||||
|
||||
function Pager (pageSize, opts) {
|
||||
if (!(this instanceof Pager)) return new Pager(pageSize, opts)
|
||||
|
||||
this.length = 0
|
||||
this.updates = []
|
||||
this.path = new Uint16Array(4)
|
||||
this.pages = new Array(32768)
|
||||
this.maxPages = this.pages.length
|
||||
this.level = 0
|
||||
this.pageSize = pageSize || 1024
|
||||
this.deduplicate = opts ? opts.deduplicate : null
|
||||
this.zeros = this.deduplicate ? alloc(this.deduplicate.length) : null
|
||||
}
|
||||
|
||||
Pager.prototype.updated = function (page) {
|
||||
while (this.deduplicate && page.buffer[page.deduplicate] === this.deduplicate[page.deduplicate]) {
|
||||
page.deduplicate++
|
||||
if (page.deduplicate === this.deduplicate.length) {
|
||||
page.deduplicate = 0
|
||||
if (page.buffer.equals && page.buffer.equals(this.deduplicate)) page.buffer = this.deduplicate
|
||||
break
|
||||
}
|
||||
}
|
||||
if (page.updated || !this.updates) return
|
||||
page.updated = true
|
||||
this.updates.push(page)
|
||||
}
|
||||
|
||||
Pager.prototype.lastUpdate = function () {
|
||||
if (!this.updates || !this.updates.length) return null
|
||||
var page = this.updates.pop()
|
||||
page.updated = false
|
||||
return page
|
||||
}
|
||||
|
||||
Pager.prototype._array = function (i, noAllocate) {
|
||||
if (i >= this.maxPages) {
|
||||
if (noAllocate) return
|
||||
grow(this, i)
|
||||
}
|
||||
|
||||
factor(i, this.path)
|
||||
|
||||
var arr = this.pages
|
||||
|
||||
for (var j = this.level; j > 0; j--) {
|
||||
var p = this.path[j]
|
||||
var next = arr[p]
|
||||
|
||||
if (!next) {
|
||||
if (noAllocate) return
|
||||
next = arr[p] = new Array(32768)
|
||||
}
|
||||
|
||||
arr = next
|
||||
}
|
||||
|
||||
return arr
|
||||
}
|
||||
|
||||
Pager.prototype.get = function (i, noAllocate) {
|
||||
var arr = this._array(i, noAllocate)
|
||||
var first = this.path[0]
|
||||
var page = arr && arr[first]
|
||||
|
||||
if (!page && !noAllocate) {
|
||||
page = arr[first] = new Page(i, alloc(this.pageSize))
|
||||
if (i >= this.length) this.length = i + 1
|
||||
}
|
||||
|
||||
if (page && page.buffer === this.deduplicate && this.deduplicate && !noAllocate) {
|
||||
page.buffer = copy(page.buffer)
|
||||
page.deduplicate = 0
|
||||
}
|
||||
|
||||
return page
|
||||
}
|
||||
|
||||
Pager.prototype.set = function (i, buf) {
|
||||
var arr = this._array(i, false)
|
||||
var first = this.path[0]
|
||||
|
||||
if (i >= this.length) this.length = i + 1
|
||||
|
||||
if (!buf || (this.zeros && buf.equals && buf.equals(this.zeros))) {
|
||||
arr[first] = undefined
|
||||
return
|
||||
}
|
||||
|
||||
if (this.deduplicate && buf.equals && buf.equals(this.deduplicate)) {
|
||||
buf = this.deduplicate
|
||||
}
|
||||
|
||||
var page = arr[first]
|
||||
var b = truncate(buf, this.pageSize)
|
||||
|
||||
if (page) page.buffer = b
|
||||
else arr[first] = new Page(i, b)
|
||||
}
|
||||
|
||||
Pager.prototype.toBuffer = function () {
|
||||
var list = new Array(this.length)
|
||||
var empty = alloc(this.pageSize)
|
||||
var ptr = 0
|
||||
|
||||
while (ptr < list.length) {
|
||||
var arr = this._array(ptr, true)
|
||||
for (var i = 0; i < 32768 && ptr < list.length; i++) {
|
||||
list[ptr++] = (arr && arr[i]) ? arr[i].buffer : empty
|
||||
}
|
||||
}
|
||||
|
||||
return Buffer.concat(list)
|
||||
}
|
||||
|
||||
function grow (pager, index) {
|
||||
while (pager.maxPages < index) {
|
||||
var old = pager.pages
|
||||
pager.pages = new Array(32768)
|
||||
pager.pages[0] = old
|
||||
pager.level++
|
||||
pager.maxPages *= 32768
|
||||
}
|
||||
}
|
||||
|
||||
function truncate (buf, len) {
|
||||
if (buf.length === len) return buf
|
||||
if (buf.length > len) return buf.slice(0, len)
|
||||
var cpy = alloc(len)
|
||||
buf.copy(cpy)
|
||||
return cpy
|
||||
}
|
||||
|
||||
function alloc (size) {
|
||||
if (Buffer.alloc) return Buffer.alloc(size)
|
||||
var buf = new Buffer(size)
|
||||
buf.fill(0)
|
||||
return buf
|
||||
}
|
||||
|
||||
function copy (buf) {
|
||||
var cpy = Buffer.allocUnsafe ? Buffer.allocUnsafe(buf.length) : new Buffer(buf.length)
|
||||
buf.copy(cpy)
|
||||
return cpy
|
||||
}
|
||||
|
||||
function Page (i, buf) {
|
||||
this.offset = i * buf.length
|
||||
this.buffer = buf
|
||||
this.updated = false
|
||||
this.deduplicate = 0
|
||||
}
|
||||
|
||||
function factor (n, out) {
|
||||
n = (n - (out[0] = (n & 32767))) / 32768
|
||||
n = (n - (out[1] = (n & 32767))) / 32768
|
||||
out[3] = ((n - (out[2] = (n & 32767))) / 32768) & 32767
|
||||
}
|
84
node_modules/memory-pager/package.json
generated
vendored
Normal file
84
node_modules/memory-pager/package.json
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"memory-pager@^1.0.2",
|
||||
"/home/beppe/Github/yahooApi/node_modules/sparse-bitfield"
|
||||
]
|
||||
],
|
||||
"_from": "memory-pager@>=1.0.2 <2.0.0",
|
||||
"_hasShrinkwrap": false,
|
||||
"_id": "memory-pager@1.5.0",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/memory-pager",
|
||||
"_nodeVersion": "10.15.0",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "s3://npm-registry-packages",
|
||||
"tmp": "tmp/memory-pager_1.5.0_1547048304675_0.7412715036396982"
|
||||
},
|
||||
"_npmUser": {
|
||||
"email": "mathiasbuus@gmail.com",
|
||||
"name": "mafintosh"
|
||||
},
|
||||
"_npmVersion": "6.4.1",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "memory-pager",
|
||||
"raw": "memory-pager@^1.0.2",
|
||||
"rawSpec": "^1.0.2",
|
||||
"scope": null,
|
||||
"spec": ">=1.0.2 <2.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/sparse-bitfield"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz",
|
||||
"_shasum": "d8751655d22d384682741c972f2c3d6dfa3e66b5",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "memory-pager@^1.0.2",
|
||||
"_where": "/home/beppe/Github/yahooApi/node_modules/sparse-bitfield",
|
||||
"author": {
|
||||
"name": "Mathias Buus",
|
||||
"url": "@mafintosh"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/mafintosh/memory-pager/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "Access memory using small fixed sized buffers",
|
||||
"devDependencies": {
|
||||
"standard": "^9.0.0",
|
||||
"tape": "^4.6.3"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"fileCount": 6,
|
||||
"integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==",
|
||||
"npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcNhVxCRA9TVsSAnZWagAADGEP/1GkISzRH2CPPqJ2K5qT\nwUoSt74qYjbPamUtndHZZ+M54VTsjURfgR6AbSVr/qNu+aqpnj9kWnw0wzJF\nqUzKMT5JEYptJMr0Bwr3Hx+90+5dOatFTlveDCHhgtdCtcl29xgGXdU2yWdu\nJKV6UNZW5VLdBkMTkmmtJCJbcCQAc2CBfI3vP3F4+n3ssOF9S2ePYW4Z7tTf\nioZ3e994D3bRkM2jz1ce0LXY3rTgjferHrjQ/y2kazJZPDcp+ofy/At+cEQD\nWkva3dgz92pRdW0LFz09rI/JzkJ3FdSlG7ZYyXuDO6Mi1u+t2UUjgUeZO3uf\nmcdwvZ155l1oLjCYRhGxbWByNhUCZBR0z4YpA8CB0aHanO3fuzda6vIxTvb0\nFokuxPzLrySdUYJ5QMzDlEodbFDxtJtMZ6NR+AU4zttNRyzIfBjDztMR6md/\n3n2FOBL9nsjd1DdesGRKSW9tFOQOFESr+jUWM9x8W9BrgTz49djUvpnmj663\nvwIYe80NSZcbGL+nQHkI9KeEO2WDeqeYmiMUkQirJncFD3XjP+/t78hAg7Ft\nPLvh9LGorjnB0kaAOyTYCIMr5Q+gDaW7B3CC14KiTpVGXMlCnuoF3s3z5lpT\nsB5H02Qx/bcKcYR43gmGKqObYAXZfRAG+S55CWfmoEC0TSnoJsYWC0zsfiKo\n5Lar\r\n=jI2j\r\n-----END PGP SIGNATURE-----\r\n",
|
||||
"shasum": "d8751655d22d384682741c972f2c3d6dfa3e66b5",
|
||||
"tarball": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz",
|
||||
"unpackedSize": 8135
|
||||
},
|
||||
"gitHead": "bccc3652145f9ceaaf1035ff1258580ca39d465d",
|
||||
"homepage": "https://github.com/mafintosh/memory-pager",
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "mafintosh",
|
||||
"email": "mathiasbuus@gmail.com"
|
||||
}
|
||||
],
|
||||
"name": "memory-pager",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/mafintosh/memory-pager.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "standard && tape test.js"
|
||||
},
|
||||
"version": "1.5.0"
|
||||
}
|
80
node_modules/memory-pager/test.js
generated
vendored
Normal file
80
node_modules/memory-pager/test.js
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
var tape = require('tape')
|
||||
var pager = require('./')
|
||||
|
||||
tape('get page', function (t) {
|
||||
var pages = pager(1024)
|
||||
|
||||
var page = pages.get(0)
|
||||
|
||||
t.same(page.offset, 0)
|
||||
t.same(page.buffer, Buffer.alloc(1024))
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('get page twice', function (t) {
|
||||
var pages = pager(1024)
|
||||
t.same(pages.length, 0)
|
||||
|
||||
var page = pages.get(0)
|
||||
|
||||
t.same(page.offset, 0)
|
||||
t.same(page.buffer, Buffer.alloc(1024))
|
||||
t.same(pages.length, 1)
|
||||
|
||||
var other = pages.get(0)
|
||||
|
||||
t.same(other, page)
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('get no mutable page', function (t) {
|
||||
var pages = pager(1024)
|
||||
|
||||
t.ok(!pages.get(141, true))
|
||||
t.ok(pages.get(141))
|
||||
t.ok(pages.get(141, true))
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('get far out page', function (t) {
|
||||
var pages = pager(1024)
|
||||
|
||||
var page = pages.get(1000000)
|
||||
|
||||
t.same(page.offset, 1000000 * 1024)
|
||||
t.same(page.buffer, Buffer.alloc(1024))
|
||||
t.same(pages.length, 1000000 + 1)
|
||||
|
||||
var other = pages.get(1)
|
||||
|
||||
t.same(other.offset, 1024)
|
||||
t.same(other.buffer, Buffer.alloc(1024))
|
||||
t.same(pages.length, 1000000 + 1)
|
||||
t.ok(other !== page)
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
tape('updates', function (t) {
|
||||
var pages = pager(1024)
|
||||
|
||||
t.same(pages.lastUpdate(), null)
|
||||
|
||||
var page = pages.get(10)
|
||||
|
||||
page.buffer[42] = 1
|
||||
pages.updated(page)
|
||||
|
||||
t.same(pages.lastUpdate(), page)
|
||||
t.same(pages.lastUpdate(), null)
|
||||
|
||||
page.buffer[42] = 2
|
||||
pages.updated(page)
|
||||
pages.updated(page)
|
||||
|
||||
t.same(pages.lastUpdate(), page)
|
||||
t.same(pages.lastUpdate(), null)
|
||||
|
||||
t.end()
|
||||
})
|
Reference in New Issue
Block a user