Home modules.gotpike.org
Username: Password: [Create Account]
[Forgot Password?]

Modules

ADT
Database
GTK2
GUI
IP
PiJAX
Public
Sql
Stdio
Subversion
System
Tools
Xosd
lua
v4l2
wx

Recent Changes

Public.Parser.XML2 1.50
Public.ZeroMQ 1.1
Public.Template.Mustache 1.0
Public.Protocols.XMPP 1.4
Sql.Provider.jdbc 1.0

Popular Downloads

Public.Parser.JSON2 1.0
Public.Parser.JSON 0.2
GTK2 2.23
Public.Web.FCGI 1.8
Public.Parser.XML2 1.48


Module Information
ADT.Tree
Viewing contents of ADT_Tree-1.1/support.c

/*
 * Time-stamp: <05/11/18 13:09:19 riffraff>
 *
 * $Id: support.c,v 1.2 2005/11/18 20:04:24 riffraff Exp $
 */

#include "global.h"
#include "module.h"
#include "interpret.h"
#include "svalue.h"
#include "stralloc.h"
#include "array.h"
#include "pike_macros.h"
#include "program.h"
#include "object.h"
#include "pike_types.h"
#include "pike_error.h"
#include "builtin_functions.h"
#include "opcodes.h"
#include "module_support.h"
#include "operators.h"
#include "mapping.h"

#include "tree.h"

#undef THIS
#define THIS ((struct atable *)(Pike_fp->current_storage))
#define THIS_PROGRAM (Pike_fp->context.prog)
#define RETURN_THIS() do{ ref_push_object(Pike_fp->current_object); }while(0)

extern struct anode sentinel;

struct pike_string *describe(struct svalue *sv, char *fmt) {
  struct svalue s;
  push_text(fmt);
  push_svalue(sv);
  f_sprintf(2);
  assign_svalue_no_free(&s,&Pike_sp[-1]);
  add_ref(s.u.string);
  pop_stack();
  free_svalue(&s);
  return s.u.string;
}

struct pike_string *describe_string(struct svalue *sv) {
  return describe(sv,"%s");
}

struct pike_string *tree_describe_type(struct svalue *sv) {
  switch (sv->type) {
    case PIKE_T_INT:
      return describe(sv,"%d");
    case PIKE_T_FLOAT:
      return describe(sv,"%f");
    case PIKE_T_STRING:
      return describe(sv,"%s");
    default:
      return describe(sv,"%O");
  }
}

int compare_svalue(struct svalue *sv1, struct svalue *sv2) {
  int cmp;

  if (sv1==NULL && sv2)
    return 1;
  if (sv2==NULL && sv1)
    return -1;
  if (sv2==NULL && sv1==NULL)
    return -1;
  if (THIS->comp_func.type==PIKE_T_INT) {
    cmp=is_eq(sv1,sv2);
    if (cmp)
      return 0;
    cmp=is_lt(sv1,sv2);
    if (cmp)
      return -1;
    return 1;
  }
  push_svalue(sv1);
  push_svalue(sv2);
  apply_svalue(&THIS->comp_func,2);
  cmp=Pike_sp[-1].u.integer;
  pop_stack();
  return cmp;
}

struct anode *create_node() {
  struct anode *n;

  n=xalloc(sizeof(struct anode));
  n->left=&sentinel;
  n->right=&sentinel;
  n->parent=&sentinel;
  n->key=xalloc(sizeof(struct svalue));
  n->val=xalloc(sizeof(struct svalue));
  return n;
}

void INLINE destroy_node(struct anode *n) {
  free_svalue(n->key);
  free(n->key);
  free_svalue(n->val);
  free(n->val);
  free(n);
}

struct anode *find_first(struct anode *n) {
  struct anode *left,*root;

  root=n;
  if (root!=&sentinel)
    while ((left=root->left)!=&sentinel)
      root=left;
  return (root==&sentinel)?NULL:root;
}

struct anode *find_last(struct anode *n) {
  struct anode *root,*right;

  root=n;
  if (root!=&sentinel)
    while ((right=root->right)!=&sentinel)
      root=right;
  return (root==&sentinel)?NULL:root;
}

struct anode *find_next(struct anode *cur) {
  struct anode *parent,*left;

  if (cur->right!=&sentinel) {
    cur=cur->right;
    while ((left=cur->left)!=&sentinel)
      cur=left;
    return cur;
  }
  parent=cur->parent;
  while (parent!=&sentinel && cur==parent->right) {
    cur=parent;
    parent=cur->parent;
  }
  return (parent==&sentinel)?NULL:parent;
}

struct anode *find_prev(struct anode *cur) {
  struct anode *parent,*right;

  if (cur->left!=&sentinel) {
    cur=cur->left;
    while ((right=cur->right)!=&sentinel)
      cur=right;
    return cur;
  }
  parent=cur->parent;
  while (parent!=&sentinel && cur==parent->left) {
    cur=parent;
    parent=cur->parent;
  }
  return (parent==&sentinel)?NULL:parent;
}

void low_tree_create(struct svalue *cb) {
  /*  THIS->root=create_node(); */
  THIS->root=&sentinel;
  if (cb) {
    assign_svalue_no_free(&THIS->comp_func,cb);
  } else {
    THIS->comp_func.type=PIKE_T_INT;
    THIS->comp_func.subtype=NUMBER_NUMBER;
    THIS->comp_func.u.integer=0;
  }
  THIS->sent=&sentinel;
  THIS->sent->left=&sentinel;
  THIS->sent->right=&sentinel;
  THIS->sent->parent=&sentinel;
  THIS->gen=THIS->count=0;
  THIS->dup=0;
  THIS->abend=0;
}



gotpike.org | Copyright © 2004 - 2019 | Pike is a trademark of Department of Computer and Information Science, Linköping University