L
Size: a a a
L
DE
L
class IDB {
constructor(dbName, objectStoreName, keyPath, indexList = []) {
this.dbName = dbName
this.objectStoreName = objectStoreName
this.keyPath = keyPath
this.indexList = indexList
this.db = null
}
async open() {
return new Promise((d,f) => {
const rqIndexDB = window.indexedDB.open(this.dbName, 3);
rqIndexDB.onerror = event => {
f(event)
}
rqIndexDB.onupgradeneeded = event => {
const db = event.target.result;
const objectStore = db.createObjectStore(this.objectStoreName, { keyPath: this.keyPath });
this.indexList.map(i => {
if ( typeof i === "string" )
i = {indexName: i, keyPath: i, unique: false}
objectStore.createIndex(i.indexName, i.keyPath, i)
})
}
rqIndexDB.onsuccess = event => {
this.db = event.target.result;
d(this.db)
}
})
}
transaction(mode = "readwrite") {
if ( !this.db )
return null
return this.db.transaction([this.objectStoreName], mode);
}
objectStore(mode = "readwrite") {
const t = this.transaction(mode)
if ( !t )
return null
return t.objectStore(this.objectStoreName)
}
}
const idb = new IDB("morewords", "words", "id", ["value"])
await idb.open()
{
const data = new Uint8Array(1024*1024)
console.time('x')
idb.objectStore().add({value: data, id: 1}).onsuccess = event => {
console.timeEnd('x')
console.log
}
}
L
DE
L
The serialized keys and/or value are too large (size=2147483723 bytes, max=133169152 bytes)
DE
const idb = new IDB("morewords", "words", "id", ["value"])
await idb.open()
const data = new Uint8Array(1024*1024)
Array.from({ length: 10 }).forEach((_, i) => {
console.time('x'+i)
idb.objectStore().add({value: data, id: i + 1}).onsuccess = event => {
console.timeEnd('x'+i)
console.log(event)
}
})
S
const { first, second, last } = (([first, ...rest]) => ({
first,
last: rest.pop(),
second: rest.join(" ")
}))(str.split(" "))
S
var macros;
var macrosrun;
var s_n = "\n";
macros = "CODE:SET !EXTRACT_TEST_POPUP NO"+s_n;
var linkList = window.document.querySelectorAll(".Groups__item");
window.console.log("Links count: ", linkList.length);
for (i=1; i<=linkList.length; i++)
{
var linkList = window.document.querySelectorAll(".Groups__item")[i].href
window.console.log(linkList);
macrosrun = iimPlay(macros);
macros = "CODE:SET !EXTRACT_TEST_POPUP NO"+s_n;
}
S
var macros;
var macrosrun;
var s_n = "\n";
macros = "CODE:SET !EXTRACT_TEST_POPUP NO"+s_n;
var linkList = window.document.querySelectorAll(".Groups__item");
window.console.log("Links count: ", linkList.length);
for (i=1; i<=linkList.length; i++){
var linkList = window.document.querySelectorAll(".Groups__item")[i].href
window.console.log(linkList);
}
function saveFile(path, content) {
var file= imns.FIO.openNode(path);
imns.FIO.writeTextFile(file,content);
}
saveFile("c:\\1\\test.txt", linkList ); // сохр в файл
macrosrun = iimPlay(macros);
macros = "CODE:SET !EXTRACT_TEST_POPUP NO"+s_n;
S
var macros;
var macrosrun;
var s_n = "\n";
macros = "CODE:SET !EXTRACT_TEST_POPUP NO"+s_n;
var linkList = window.document.querySelectorAll(".Groups__item");
window.console.log("Links count: ", linkList.length);
for (i=1; i<=linkList.length; i++)
{
var linkList = window.document.querySelectorAll(".Groups__item")[i].href
window.console.log(linkList);
macrosrun = iimPlay(macros);
macros = "CODE:SET !EXTRACT_TEST_POPUP NO"+s_n;
}
S
var macros;
var macrosrun;
var s_n = "\n";
macros = "CODE:SET !EXTRACT_TEST_POPUP NO"+s_n;
var linkList = window.document.querySelectorAll(".Groups__item");
window.console.log("Links count: ", linkList.length);
for (i=1; i<=linkList.length; i++){
var linkList = window.document.querySelectorAll(".Groups__item")[i].href
window.console.log(linkList);
}
function saveFile(path, content) {
var file= imns.FIO.openNode(path);
imns.FIO.writeTextFile(file,content);
}
saveFile("c:\\1\\test.txt", linkList ); // сохр в файл
macrosrun = iimPlay(macros);
macros = "CODE:SET !EXTRACT_TEST_POPUP NO"+s_n;
S
function asmjsModule() {( та с ошбикой была скопирована )
function asmjs(stdlib, env, heap) {
"use asm";
const i32array = new stdlib.Int32Array(heap)
function init(iNumBits) {
iNumBits = iNumBits|0
var iLen = 0, i = 0
iLen = ((iNumBits >> 5) + 1)|0
for(i = 0|0; (i|0) < (iLen|0); i = (i+1)|0)
i32array[i<<2>>2] = 0
}
function add(iStart, iEnd) {
iStart = iStart|0
iEnd = iEnd|0
var iLen = 0, iOffset = 0
iLen = (iEnd - iStart)|0
iOffset = iStart >> 5
if ( (iLen|0) <= 32 ) {
if ( ( (iStart & 31) + iLen|0 ) >= 32 ) {
i32array[ iOffset << 2 >> 2 ] = i32array[ iOffset << 2 >> 2 ] ^ ~((1 << (iStart & 31)) - 1)
i32array[ (iEnd >> 3) >> 2 ] = i32array[ (iEnd >> 3) >> 2 ] ^ ( (1 << ((iEnd & 31))) - 1 )
return
}
i32array[ iOffset << 2 >> 2 ] = i32array[ iOffset << 2 >> 2 ] ^ ( ((1 << iLen) - 1) << iStart )
return
}
i32array[ iOffset << 2 >> 2 ] = i32array[ iOffset << 2 >> 2 ] ^ ~((1 << (iStart & 31)) - 1)
iOffset = (iOffset + 1)|0
for(; (iOffset|0) < (iEnd >> 5); iOffset = (iOffset + 1)|0)
i32array[ iOffset << 2 >> 2 ] = i32array[ iOffset << 2 >> 2 ] ^ -1
i32array[ iOffset << 2 >> 2 ] = i32array[ iOffset << 2 >> 2 ] ^ ( (1 << ((iEnd & 31))) - 1 )
}
function get(iBits) {
iBits = iBits | 0
return ( i32array[ (iBits >> 3) >> 2 ] >> (iBits & 31) ) & 1
}
return { init: init, add: add, get: get }
}
const heap = new ArrayBuffer(1024*1024)
return asmjs( {
Uint8Array: Uint8Array,
Int8Array: Int8Array,
Uint16Array: Uint16Array,
Int16Array: Int16Array,
Uint32Array: Uint32Array,
Int32Array: Int32Array,
Float32Array:Float32Array,
Float64Array:Float64Array,
Math: Math
},
{},
heap
)
}
const module = asmjsModule()
const moduleSegments = asmjsModule()
const SEGMENT_BITS = 10
function binarySimulation(s, q) {
module.init(s.length)
moduleSegments.init((s.length >> SEGMENT_BITS) + 1)
const r = []
for(const v of q) {
switch(v[0]) {
case "I":
let [, start, end] = v
start--
const startSeg = (start >> SEGMENT_BITS) + 1
const endSeg = end >> SEGMENT_BITS
if ( startSeg <= endSeg ) {
moduleSegments.add(startSeg, endSeg)
module.add(start, startSeg << SEGMENT_BITS)
module.add(endSeg << SEGMENT_BITS, end)
break
}
module.add(start, end)
break
case "Q":
const i = v[1] - 1
r.push( '' + (
module.get(i) ^
moduleSegments.get(i >> SEGMENT_BITS) ^
s[i]
) )
break
}
}
return r
}
S
class Vector {
constructor(len, bits = 0) {
this.bits = bits
this.array = new Uint8Array(len)
}
init(len) {
this.array.fill(0, 0, len)
}
add(start, end) {
for(let i = start; i < end; i++)
this.array[i] ^= 1
}
get(i) {
return this.array[i]
}
}
const SEGMENT_BITS_6 = 4
const SEGMENT_BITS_10 = 7
const SEGMENT_BITS_15 = 12
const vec = new Vector(100e3)
const vecSeg6 = new Vector((100e3 >> SEGMENT_BITS_6) + 1)
const vecSeg10 = new Vector((100e3 >> SEGMENT_BITS_10) + 1)
const vecSeg15 = new Vector((100e3 >> SEGMENT_BITS_15) + 1)
const genAdd = (addThis, addNext, SEGMENT_BITS) =>
(start, end) => {
const startSeg = (start >> SEGMENT_BITS) + 1
const endSeg = end >> SEGMENT_BITS
if ( startSeg <= endSeg ) {
addThis(startSeg, endSeg)
addNext(start, startSeg << SEGMENT_BITS)
addNext(endSeg << SEGMENT_BITS, end)
return
}
addNext(start, end)
}
const add = genAdd(
(s, e) => vecSeg15.add(s, e),
genAdd(
(s, e) => vecSeg10.add(s, e),
genAdd(
(s, e) => vecSeg6.add(s, e),
(s, e) => vec.add(s, e),
SEGMENT_BITS_6
),
SEGMENT_BITS_10
),
SEGMENT_BITS_15
)
const get = i => vecSeg15.get(i >> SEGMENT_BITS_15) ^ vecSeg10.get(i >> SEGMENT_BITS_10) ^ vecSeg6.get(i >> SEGMENT_BITS_6) ^ vec.get(i)
function binarySimulation(s, q) {
vec.init(s.length)
vecSeg6.init((s.length >> SEGMENT_BITS_6) + 1)
vecSeg10.init((s.length >> SEGMENT_BITS_10) + 1)
vecSeg15.init((s.length >> SEGMENT_BITS_15) + 1)
const r = []
for(const v of q) {
switch(v[0]) {
case "I":
add(v[1] - 1, v[2])
break
case "Q":
const i = v[1] - 1
r.push( '' + ( get(i) ^ s[i] ) )
break
}
}
return r
}
S
var linkList = window.document.querySelectorAll(".Groups__item");Почему-то неверно орабатывает цикл, при подсчете должно быть 120 интераций, а на деле выходит всего 26
let arr = [];
window.console.log("Links count: ", linkList.length);
for (i=0; i <= linkList.length; i++){
var linkList = window.document.querySelectorAll(".Groups__item")[i].href
arr.push(linkList)
window.console.log(i);
}
S
const greatestProduct = s => sя так решил
.split("")
.reduce((m, v, i, a) =>
i > a.length - 5 ? m :
Math.max(m, a.slice(i, i + 5).reduce((s, v) => s * v, 1)),
Number.NEGATIVE_INFINITY)
S
function greatestProduct(digitsStr) {
let maxProduct = Number.NEGATIVE_INFINITY;
let offset = 0
while (true) {
let get5 = digitsStr.substr(offset, 5)
if ( get5.length < 5 ) break
let product = get5.split('').reduce( (a, b) => a * b, 1 )
if ( product > maxProduct )
maxProduct = product
offset++
}
return maxProduct
}
DE
L
const idb = new IDB("morewords", "words", "id", ["value"])
await idb.open()
const data = new Uint8Array(1024*1024)
Array.from({ length: 10 }).forEach((_, i) => {
console.time('x'+i)
idb.objectStore().add({value: data, id: i + 1}).onsuccess = event => {
console.timeEnd('x'+i)
console.log(event)
}
})
async function add(idb, obj) {
return new Promise((d, f) => {
const rq = idb.objectStore().add(obj)
rq.onsuccess = event => {
d(event)
}
rq.onerror = event => {
f(event)
}
})
}
console.time('x')
for(let i = 0; i < 100; i++)
await add(idb, { id: Date.now() + i, value: new Uint8Array(1024*1024) })
console.timeEnd('x')
S
async function add(idb, obj) {
return new Promise((d, f) => {
const rq = idb.objectStore().add(obj)
rq.onsuccess = event => {
d(event)
}
rq.onerror = event => {
f(event)
}
})
}
console.time('x')
for(let i = 0; i < 100; i++)
await add(idb, { id: Date.now() + i, value: new Uint8Array(1024*1024) })
console.timeEnd('x')