Class Relation

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") @Deprecated public class Relation extends ProxyInstance
Deprecated.
Rarely used API

A GRelation is a table of data which can be indexed on any number of fields, rather like simple database tables. A GRelation contains a number of records, called tuples. Each record contains a number of fields. Records are not ordered, so it is not possible to find the record at a particular index.

Note that GRelation tables are currently limited to 2 fields.

To create a GRelation, use new_(int).

To specify which fields should be indexed, use index(int, HashFunc, EqualFunc). Note that this must be called before any tuples are added to the GRelation.

To add records to a GRelation use insert(Object...).

To determine if a given record appears in a GRelation, use exists(Object...). Note that fields are compared directly, so pointers must point to the exact same position (i.e. different copies of the same string will not match.)

To count the number of records which have a particular value in a given field, use count(MemorySegment, int).

To get all the records which have a particular value in a given field, use select(MemorySegment, int). To access fields of the resulting records, use Tuples.index(int, int). To free the resulting records use Tuples.destroy().

To delete all records which have a particular value in a given field, use delete(MemorySegment, int).

To destroy the GRelation, use destroy().

To help debug GRelation objects, use print().

GRelation has been marked as deprecated, since this API has never been fully implemented, is not very actively maintained and rarely used.

  • Constructor Details

    • Relation

      public Relation(MemorySegment address)
      Deprecated.
      Create a Relation proxy instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
  • Method Details

    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      Deprecated.
      The memory layout of the native struct.
      Returns:
      the memory layout
    • new_

      @Deprecated public static Relation new_(int fields)
      Deprecated.
      Rarely used API
      Creates a new GRelation with the given number of fields. Note that currently the number of fields must be 2.
      Parameters:
      fields - the number of fields.
      Returns:
      a new GRelation.
    • count

      @Deprecated public int count(@Nullable MemorySegment key, int field)
      Deprecated.
      Rarely used API
      Returns the number of tuples in a GRelation that have the given value in the given field.
      Parameters:
      key - the value to compare with.
      field - the field of each record to match.
      Returns:
      the number of matches.
    • delete

      @Deprecated public int delete(@Nullable MemorySegment key, int field)
      Deprecated.
      Rarely used API
      Deletes any records from a GRelation that have the given key value in the given field.
      Parameters:
      key - the value to compare with.
      field - the field of each record to match.
      Returns:
      the number of records deleted.
    • destroy

      @Deprecated public void destroy()
      Deprecated.
      Rarely used API
      Destroys the GRelation, freeing all memory allocated. However, it does not free memory allocated for the tuple data, so you should free that first if appropriate.
    • exists

      @Deprecated public boolean exists(Object... varargs)
      Deprecated.
      Rarely used API
      Returns true if a record with the given values exists in a GRelation. Note that the values are compared directly, so that, for example, two copies of the same string will not match.
      Parameters:
      varargs - the fields of the record to compare. The number must match the number of fields in the GRelation.
      Returns:
      true if a record matches.
    • index

      @Deprecated public void index(int field, @Nullable HashFunc hashFunc, @Nullable EqualFunc keyEqualFunc)
      Deprecated.
      Rarely used API
      Creates an index on the given field. Note that this must be called before any records are added to the GRelation.
      Parameters:
      field - the field to index, counting from 0.
      hashFunc - a function to produce a hash value from the field data.
      keyEqualFunc - a function to compare two values of the given field.
    • insert

      @Deprecated public void insert(Object... varargs)
      Deprecated.
      Rarely used API
      Inserts a record into a GRelation.
      Parameters:
      varargs - the fields of the record to add. These must match the number of fields in the GRelation, and of type gpointer or gconstpointer.
    • print

      @Deprecated public void print()
      Deprecated.
      Rarely used API
      Outputs information about all records in a GRelation, as well as the indexes. It is for debugging.
    • select

      @Deprecated public Tuples select(@Nullable MemorySegment key, int field)
      Deprecated.
      Rarely used API
      Returns all of the tuples which have the given key in the given field. Use g_tuples_index() to access the returned records. The returned records should be freed with g_tuples_destroy().
      Parameters:
      key - the value to compare with.
      field - the field of each record to match.
      Returns:
      the records (tuples) that matched.