Created
December 12, 2012 05:04
-
-
Save dherman/4265013 to your computer and use it in GitHub Desktop.
pointer type approach
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var IPAddress = new ArrayType(uint8, 4); | |
var P_IPAddress = new PointerType(IPAddress); | |
var Packet = new StructType({ addr: IPAddress, ... }); | |
var P_Packet = new PointerType(Packet); | |
var PacketArray = new ArrayType(Packet); | |
var lotsOfPackets = new PacketArray(LOTS); | |
for (let p of lotsOfPackets.cursor("addr")) { | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+-------------+ +-----------------------+ | |
| |---------->| | | |
| PointerType | | PointerType.prototype | | |
| |<----------| | | |
+-------------+ +-----------------------+ | |
^ | |
| | |
| | |
+-----------------------+ +-------------+ | |
| |---------->| | | |
| T | | T.prototype | | |
| |<----------| | | |
+-----------------------+ +-------------+ | |
^ | |
| | |
| | |
+-------------+ | |
| | | |
| p | | |
| | | |
+-------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b ::= int8 | uint8 | int16 | uint16 | int32 | uint32 | float32 | float64 | |
t ::= b | s | *s | |
s ::= [t x k] | { x1: t1, ..., xn: tn } |
But more broadly, it also violates expectations if updating a pointer involves an O(n) check (where n is the size of the type, not the data structure, but still). So I really wanted to avoid structural type checks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Right.