Gryphon Data Structures

From Adam Colton
Jump to navigation Jump to search

Built in

Very little by default. Not even arrays. There is something like a byte array.

Struct

The default data structure. Definition is surrounded by angle brackets, or possibly angle brackets plus the type bracket. If the type bracket is [] it would be

 person := <[
   Name : string
   Age : int
 ]>

I'm not sure yet what the type bracket will be. I like using {} for list so that code blocks stay as curly braces. I end up liking (), but then it would be weird to us that for math. That leaves [], but I'm not sure how I feel about that.

 adam := person[
   Name = "Adam"
   Age = 35
 ]

Unlike Go, there are no default values, but default values can be provided

 person := <[
   Name : string = "John Doe"
   Age : int
 ]>

When instantiating, any field without a default value must be defined.

Curry

Need this, not sure:

 partial := person<
   Name = "Adam"
 >
 adam := partial[
   Age = 35
 ]

Lists

Lists are of the form

 {a; b; c; d}

It frees up the comma and it's faster because ; is under the pinky. Newlines can also be used

 {
   a
   b
   c
   d
 }

A list is neither a slice nor an array. It's type is constant and it is immutable.

Std Lib

Array

This is a package off the standard library

Fixed

This is the Go array. The size is baked into the type

 foo:= Array.Fixed<int,4>()

Variable

Like a slice, but has no excess capacity. Unlike fixed, different lengths are the same type.

 foo := Array.Var<int>(10)

Slice/Vector

The Go slice, has both a length and capacity.

SOA

This will be a good challenge for design. From Jai (Jonathan Blow's language). The element type is broken into it's fields, the array is allocated in one memory block, but the fields are grouped. So

 people := Array.SOA<Person>(20)

would be like

 people := struct{
   Name: Array.Var<string>(20)
   Age : Array.Var<int>(20)
 }

Except that since 20 is constant across both, it's only stored once.

But making this work would require exposing private fields to the Array library. One solution that may make sense would be to allow unsafe libraries to access private fields. Since they can do pointer math, they basically can anyway.

Channel

Depending on mutability, I think these will be different from the Go channel. I think you setup a receiver and then create senders. Each sender is a separate but mutable instance.

Hash Map

Yup.

Trees

  • Red/Black
  • B
  • KD

I think it may be possible to create one general purpose tree. It has a B value where B=1 is a binary tree. It can also be KT by passing the depth into the compare function.