pointer-set
Advanced tools
Comparing version 1.0.5 to 1.1.0
@@ -250,2 +250,36 @@ declare const max16 = 65536; | ||
/** | ||
* Get the raw data from the supplied pointer, in the supplied rawField, | ||
* as a 4-byte Uint8Array view. Editing the view will update the value. | ||
*/ | ||
raw8(pointer: Pointer, field: FieldName<R>): Uint8Array; | ||
/** | ||
* Set the raw data for the supplied pointer, in the supplied rawField, | ||
* to the values set in a 4-byte Uint8Array. Returns a 4-byte Uint8Array | ||
* view. Editing the view will update the value. | ||
*/ | ||
raw8(pointer: Pointer, field: FieldName<R>, val: Uint8Array): Uint8Array; | ||
/** | ||
* Get the raw data from the supplied pointer, in the supplied rawField, | ||
* as a 2-word Uint16Array view. Editing the view will update the value. | ||
*/ | ||
raw16(pointer: Pointer, field: FieldName<R>): Uint16Array; | ||
/** | ||
* Set the raw data for the supplied pointer, in the supplied rawField, | ||
* to the values set in a 2-word Uint16Array. Returns a 2-word Uint16Array | ||
* view. Editing the view will update the value. | ||
*/ | ||
raw16(pointer: Pointer, field: FieldName<R>, val: Uint16Array): Uint16Array; | ||
/** | ||
* Get the raw data from the supplied pointer, in the supplied rawField, | ||
* as a 1-word Uint32Array view. Editing the view will update the value. | ||
*/ | ||
raw32(pointer: Pointer, field: FieldName<R>): Uint32Array; | ||
/** | ||
* Set the raw data for the supplied pointer, in the supplied rawField, | ||
* to the values set in a 1-word Uint32Array. Returns a 1-word Uint32Array | ||
* view. Editing the view will update the value. | ||
*/ | ||
raw32(pointer: Pointer, field: FieldName<R>, val: Uint32Array): Uint32Array; | ||
getRawSlab(pointer: Pointer, field: FieldName<R>): Uint32Array; | ||
/** | ||
* Get the data for a given pointer from the `values` array | ||
@@ -471,2 +505,33 @@ */ | ||
/** | ||
* Get the raw data from the supplied pointer, in the supplied rawField, | ||
* as a 4-byte Uint8Array view. Editing the view will update the value. | ||
*/ | ||
raw8(pointer: Pointer, field: FieldName<R>): Uint8Array; | ||
/** | ||
* Get the raw data from the supplied pointer, in the supplied rawField, | ||
* as a 4-byte Uint8Array view. Editing the view will update the value. | ||
*/ | ||
raw8(pointer: Pointer, field: FieldName<R>, val: Uint8Array): Uint8Array; | ||
/** | ||
* Get the raw data from the supplied pointer, in the supplied rawField, | ||
* as a 2-word Uint16Array view. Editing the view will update the value. | ||
*/ | ||
raw16(pointer: Pointer, field: FieldName<R>): Uint16Array; | ||
/** | ||
* Get the raw data from the supplied pointer, in the supplied rawField, | ||
* as a 2-word Uint16Array view. Editing the view will update the value. | ||
*/ | ||
raw16(pointer: Pointer, field: FieldName<R>, val: Uint16Array): Uint16Array; | ||
/** | ||
* Get the raw data from the supplied pointer, in the supplied rawField, | ||
* as a 1-word Uint32Array view. Editing the view will update the value. | ||
*/ | ||
raw32(pointer: Pointer, field: FieldName<R>): Uint32Array; | ||
/** | ||
* Get the raw data from the supplied pointer, in the supplied rawField, | ||
* as a 1-word Uint32Array view. Editing the view will update the value. | ||
*/ | ||
raw32(pointer: Pointer, field: FieldName<R>, val: Uint32Array): Uint32Array; | ||
getRawSlab(pointer: Pointer, field: FieldName<R>): Uint32Array; | ||
/** | ||
* Get the data for a given pointer from the `values` array | ||
@@ -473,0 +538,0 @@ */ |
@@ -420,4 +420,44 @@ "use strict"; | ||
noNullPointer(pointer, val); | ||
const index = this.getIndex(pointer); | ||
const slab = this.getRawSlab(pointer, field); | ||
if (val === undefined) { | ||
return slab[index]; | ||
} | ||
else { | ||
return (slab[index] = val); | ||
} | ||
} | ||
raw8(pointer, field, val) { | ||
const index = this.getIndex(pointer); | ||
const slab = this.getRawSlab(pointer, field); | ||
const view = new Uint8Array(slab.buffer, slab.byteOffset + index * 4, 4); | ||
if (val !== undefined) { | ||
view[0] = val[0]; | ||
view[1] = val[1]; | ||
view[2] = val[2]; | ||
view[3] = val[3]; | ||
} | ||
return view; | ||
} | ||
raw16(pointer, field, val) { | ||
const index = this.getIndex(pointer); | ||
const slab = this.getRawSlab(pointer, field); | ||
const view = new Uint16Array(slab.buffer, slab.byteOffset + index * 4, 2); | ||
if (val !== undefined) { | ||
view[0] = val[0]; | ||
view[1] = val[1]; | ||
} | ||
return view; | ||
} | ||
raw32(pointer, field, val) { | ||
const slab = this.getRawSlab(pointer, field); | ||
const index = this.getIndex(pointer); | ||
const view = new Uint32Array(slab.buffer, slab.byteOffset + index * 4, 1); | ||
if (val !== undefined) { | ||
view[0] = val[0]; | ||
} | ||
return view; | ||
} | ||
getRawSlab(pointer, field) { | ||
const blockId = this.getBlockId(pointer); | ||
const index = this.getIndex(pointer); | ||
const fieldId = this.names[field]; | ||
@@ -431,8 +471,3 @@ if (fieldId >= 0) { | ||
} | ||
if (val === undefined) { | ||
return slab[index]; | ||
} | ||
else { | ||
return (slab[index] = val); | ||
} | ||
return slab; | ||
} | ||
@@ -439,0 +474,0 @@ value(pointer, val) { |
@@ -250,2 +250,36 @@ declare const max16 = 65536; | ||
/** | ||
* Get the raw data from the supplied pointer, in the supplied rawField, | ||
* as a 4-byte Uint8Array view. Editing the view will update the value. | ||
*/ | ||
raw8(pointer: Pointer, field: FieldName<R>): Uint8Array; | ||
/** | ||
* Set the raw data for the supplied pointer, in the supplied rawField, | ||
* to the values set in a 4-byte Uint8Array. Returns a 4-byte Uint8Array | ||
* view. Editing the view will update the value. | ||
*/ | ||
raw8(pointer: Pointer, field: FieldName<R>, val: Uint8Array): Uint8Array; | ||
/** | ||
* Get the raw data from the supplied pointer, in the supplied rawField, | ||
* as a 2-word Uint16Array view. Editing the view will update the value. | ||
*/ | ||
raw16(pointer: Pointer, field: FieldName<R>): Uint16Array; | ||
/** | ||
* Set the raw data for the supplied pointer, in the supplied rawField, | ||
* to the values set in a 2-word Uint16Array. Returns a 2-word Uint16Array | ||
* view. Editing the view will update the value. | ||
*/ | ||
raw16(pointer: Pointer, field: FieldName<R>, val: Uint16Array): Uint16Array; | ||
/** | ||
* Get the raw data from the supplied pointer, in the supplied rawField, | ||
* as a 1-word Uint32Array view. Editing the view will update the value. | ||
*/ | ||
raw32(pointer: Pointer, field: FieldName<R>): Uint32Array; | ||
/** | ||
* Set the raw data for the supplied pointer, in the supplied rawField, | ||
* to the values set in a 1-word Uint32Array. Returns a 1-word Uint32Array | ||
* view. Editing the view will update the value. | ||
*/ | ||
raw32(pointer: Pointer, field: FieldName<R>, val: Uint32Array): Uint32Array; | ||
getRawSlab(pointer: Pointer, field: FieldName<R>): Uint32Array; | ||
/** | ||
* Get the data for a given pointer from the `values` array | ||
@@ -471,2 +505,33 @@ */ | ||
/** | ||
* Get the raw data from the supplied pointer, in the supplied rawField, | ||
* as a 4-byte Uint8Array view. Editing the view will update the value. | ||
*/ | ||
raw8(pointer: Pointer, field: FieldName<R>): Uint8Array; | ||
/** | ||
* Get the raw data from the supplied pointer, in the supplied rawField, | ||
* as a 4-byte Uint8Array view. Editing the view will update the value. | ||
*/ | ||
raw8(pointer: Pointer, field: FieldName<R>, val: Uint8Array): Uint8Array; | ||
/** | ||
* Get the raw data from the supplied pointer, in the supplied rawField, | ||
* as a 2-word Uint16Array view. Editing the view will update the value. | ||
*/ | ||
raw16(pointer: Pointer, field: FieldName<R>): Uint16Array; | ||
/** | ||
* Get the raw data from the supplied pointer, in the supplied rawField, | ||
* as a 2-word Uint16Array view. Editing the view will update the value. | ||
*/ | ||
raw16(pointer: Pointer, field: FieldName<R>, val: Uint16Array): Uint16Array; | ||
/** | ||
* Get the raw data from the supplied pointer, in the supplied rawField, | ||
* as a 1-word Uint32Array view. Editing the view will update the value. | ||
*/ | ||
raw32(pointer: Pointer, field: FieldName<R>): Uint32Array; | ||
/** | ||
* Get the raw data from the supplied pointer, in the supplied rawField, | ||
* as a 1-word Uint32Array view. Editing the view will update the value. | ||
*/ | ||
raw32(pointer: Pointer, field: FieldName<R>, val: Uint32Array): Uint32Array; | ||
getRawSlab(pointer: Pointer, field: FieldName<R>): Uint32Array; | ||
/** | ||
* Get the data for a given pointer from the `values` array | ||
@@ -473,0 +538,0 @@ */ |
@@ -413,4 +413,44 @@ const max8 = 256; | ||
noNullPointer(pointer, val); | ||
const index = this.getIndex(pointer); | ||
const slab = this.getRawSlab(pointer, field); | ||
if (val === undefined) { | ||
return slab[index]; | ||
} | ||
else { | ||
return (slab[index] = val); | ||
} | ||
} | ||
raw8(pointer, field, val) { | ||
const index = this.getIndex(pointer); | ||
const slab = this.getRawSlab(pointer, field); | ||
const view = new Uint8Array(slab.buffer, slab.byteOffset + index * 4, 4); | ||
if (val !== undefined) { | ||
view[0] = val[0]; | ||
view[1] = val[1]; | ||
view[2] = val[2]; | ||
view[3] = val[3]; | ||
} | ||
return view; | ||
} | ||
raw16(pointer, field, val) { | ||
const index = this.getIndex(pointer); | ||
const slab = this.getRawSlab(pointer, field); | ||
const view = new Uint16Array(slab.buffer, slab.byteOffset + index * 4, 2); | ||
if (val !== undefined) { | ||
view[0] = val[0]; | ||
view[1] = val[1]; | ||
} | ||
return view; | ||
} | ||
raw32(pointer, field, val) { | ||
const slab = this.getRawSlab(pointer, field); | ||
const index = this.getIndex(pointer); | ||
const view = new Uint32Array(slab.buffer, slab.byteOffset + index * 4, 1); | ||
if (val !== undefined) { | ||
view[0] = val[0]; | ||
} | ||
return view; | ||
} | ||
getRawSlab(pointer, field) { | ||
const blockId = this.getBlockId(pointer); | ||
const index = this.getIndex(pointer); | ||
const fieldId = this.names[field]; | ||
@@ -424,8 +464,3 @@ if (fieldId >= 0) { | ||
} | ||
if (val === undefined) { | ||
return slab[index]; | ||
} | ||
else { | ||
return (slab[index] = val); | ||
} | ||
return slab; | ||
} | ||
@@ -432,0 +467,0 @@ value(pointer, val) { |
{ | ||
"name": "pointer-set", | ||
"version": "1.0.5", | ||
"version": "1.1.0", | ||
"description": "set of values with pointers to other entries, backed by auto=-expanding UintArray slabs", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -146,3 +146,3 @@ # pointer-set | ||
A pointer is just a number in the unsigned 32 bit range (ie, | ||
between `0` and `2**32 - 1`). The exported type is branded with | ||
between `0` and `2**32 - 1`). The exported type is branded with | ||
a unique symbol. | ||
@@ -152,3 +152,3 @@ | ||
this branded type, to prevent you from accentally using a pointer | ||
reference that was not provided by this library. However, for | ||
reference that was not provided by this library. However, for | ||
cases where you may need to cast to the type, it's exported. | ||
@@ -162,3 +162,3 @@ | ||
The type `T` can be anything except `undefined`. (If you aren't | ||
The type `T` can be anything except `undefined`. (If you aren't | ||
storing JavaScript values, `null` is a good option.) | ||
@@ -402,3 +402,3 @@ | ||
The total number of available entry slots in all blocks in the | ||
PointerSet. Note that the storage will expand on demand, so this | ||
PointerSet. Note that the storage will expand on demand, so this | ||
is actually just the number of entries that can be set before | ||
@@ -487,2 +487,38 @@ another allocation will occur. | ||
### `store.raw8(pointer: Pointer, field: FieldName<R>): Uint8Array` | ||
Specify one of the names provided in the `rawFields` list, and | ||
get an editable 4-byte Uint8Array view of the underlying bytes. | ||
### `store.raw8(pointer: Pointer, field: FieldName<R>, val: Uint8Array): Uint8Array` | ||
Specify one of the names provided in the `rawFields` list, and | ||
set the bytes to those specified in the supplied 4-byte | ||
Uint8Array. Returns an editable 4-byte Uint8Array view of the | ||
underlying bytes. | ||
### `store.raw16(pointer: Pointer, field: FieldName<R>): Uint16Array` | ||
Specify one of the names provided in the `rawFields` list, and | ||
get an editable 2-word Uint16Array view of the underlying bytes. | ||
### `store.raw16(pointer: Pointer, field: FieldName<R>, val: Uint16Array): Uint16Array` | ||
Specify one of the names provided in the `rawFields` list, and | ||
set the bytes to those specified in the supplied 2-word | ||
Uint16Array. Returns an editable 2-word Uint16Array view of the | ||
underlying bytes. | ||
### `store.raw32(pointer: Pointer, field: FieldName<R>): Uint32Array` | ||
Specify one of the names provided in the `rawFields` list, and | ||
get an editable 1-word Uint32Array view of the underlying bytes. | ||
### `store.raw32(pointer: Pointer, field: FieldName<R>, val: Uint32Array): Uint32Array` | ||
Specify one of the names provided in the `rawFields` list, and | ||
set the bytes to those specified in the supplied 1-word | ||
Uint32Array. Returns an editable 1-word Uint32Array view of the | ||
underlying bytes. | ||
### `store.rawAll(pointer: Pointer) => raws` | ||
@@ -514,3 +550,3 @@ | ||
Throws if the block has entries, or if any subsequent blocks | ||
exist. When called on the root block, calls `store.wipeBlock()` | ||
exist. When called on the root block, calls `store.wipeBlock()` | ||
instead. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
152626
2575
547