How to use the sorted-array-functions.lte function in sorted-array-functions

To help you get started, we’ve selected a few sorted-array-functions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github davidmarkclements / proffer / lib / core-events / code-move.js View on Github external
const index = sorted.lte(state.addresses, from)
    if (index === -1) {
      opts.warn(`${event} address ${fromAddr} not found`)
      cb()
      return
    }
    const entry = state.code[state.addresses[index]]
    const edge = to + entry[SIZE]

    sorted.remove(state.addresses, from)
    state.code[from] = undefined

    // clear out entries in what will be the new address range of the moved entry
    var addr = edge - 1
    while (addr >= to) {
      const ix = sorted.lte(state.addresses, addr)
      if (ix === -1) break
      const match = state.addresses[ix]
      addr = match - 1
      // code previously cleared:
      if (state.code[match] === undefined) {
        sorted.remove(state.addresses, match)
        continue
      }
      if (match + +state.code[match][SIZE] <= to) continue

      sorted.remove(state.addresses, match)
      state.code[match] = undefined
    }

    entry[START] = toAddr
    state.code[to] = entry
github davidmarkclements / proffer / lib / core-events / code-move.js View on Github external
return function (row, cb) {
    const [event, fromAddr, toAddr] = row
    const from = parseInt(fromAddr, 16)
    const to = parseInt(toAddr, 16)

    const index = sorted.lte(state.addresses, from)
    if (index === -1) {
      opts.warn(`${event} address ${fromAddr} not found`)
      cb()
      return
    }
    const entry = state.code[state.addresses[index]]
    const edge = to + entry[SIZE]

    sorted.remove(state.addresses, from)
    state.code[from] = undefined

    // clear out entries in what will be the new address range of the moved entry
    var addr = edge - 1
    while (addr >= to) {
      const ix = sorted.lte(state.addresses, addr)
      if (ix === -1) break
github mafintosh / multi-random-access / index.js View on Github external
Storage.prototype._get = function (offset) {
  if (this._last) { // high chance that we'll hit the same at least twice
    if (this._last.start <= offset && this._last.end > offset) return this._last
  }

  var i = sorted.lte(this.stores, {start: offset}, cmp)
  if (i === -1) return null

  var next = this.stores[i]
  if (next.start <= offset && next.end > offset) {
    this._last = next
    return next
  }

  return null
}
github mafintosh / hyperdrive / storage.js View on Github external
Storage.prototype._get = function (offset) {
  var i = fns.lte(this._opened, {start: offset}, cmp)
  if (i === -1) return null
  var file = this._opened[i]
  return offset < file.end ? file : null
}
github davidmarkclements / proffer / lib / core-events / tick.js View on Github external
const ix = sorted.lte(state.addresses, extCbOrTos)
      if (ix > -1) {
        const match = state.code[state.addresses[ix]]
        const isJsFunction = match[FUNC] && match.cs
        if (isJsFunction) stack.unshift(extCbOrTos)
      }
    }

    for (const i in stack) {
      var addr = parseInt(stack[i], 16)
      const codeAddr = state.addresses[sorted.lte(state.addresses, addr)]
      stack[i] = state.code[codeAddr] || { name: stack[i] }

      if (stack[i].type === 'LIB') {
        await loadSymbols(stack[i])
        const codeAddr = state.addresses[sorted.lte(state.addresses, addr)]
        stack[i] = state.code[codeAddr]
      }
    }

    const vm = vmMap(vmState)

    cb(null, {
      event,
      [PC]: pc,
      ts,
      [IS_EXT_CB]: isExtCb,
      [EXT_CB_OR_TOS]: extCbOrTos,
      [VM_STATE]: vmState,
      vm,
      stack: stack.reverse()
    })
github davidmarkclements / proffer / lib / core-events / tick.js View on Github external
return async function (row, cb) {
    const [
      event, pc, ts, isExtCb, extCbOrTos, vmState, ...stack
    ] = row

    if (isExtCb === '1') {
      stack.unshift(extCbOrTos)
    } else {
      stack.unshift(pc)
      const ix = sorted.lte(state.addresses, extCbOrTos)
      if (ix > -1) {
        const match = state.code[state.addresses[ix]]
        const isJsFunction = match[FUNC] && match.cs
        if (isJsFunction) stack.unshift(extCbOrTos)
      }
    }

    for (const i in stack) {
      var addr = parseInt(stack[i], 16)
      const codeAddr = state.addresses[sorted.lte(state.addresses, addr)]
      stack[i] = state.code[codeAddr] || { name: stack[i] }

      if (stack[i].type === 'LIB') {
        await loadSymbols(stack[i])
        const codeAddr = state.addresses[sorted.lte(state.addresses, addr)]
        stack[i] = state.code[codeAddr]

sorted-array-functions

Maintain and search through a sorted array using some low level functions

MIT
Latest version published 4 years ago

Package Health Score

65 / 100
Full package analysis

Similar packages