Esempio n. 1
0
bool BTIndexPage::get_sibling(const void *key, AttrType key_type,
		PageId &pageNo, int &left)
{
	if (slotCnt == 0) // there is no sibling
		return false;

	int i;
	for (i=slotCnt-1; i >= 0; i--) {
		get_key_data(NULL, (Datatype *) &pageNo,
				(KeyDataEntry *)(data+slot[-i].offset),
				slot[-i].length, (nodetype)type);
		if (keyCompare(key, (void*)(data+slot[-i].offset), key_type) >= 0) {
			left = 1;
			if (i != 0) {
				get_key_data(NULL, (Datatype *) &pageNo,
						(KeyDataEntry *)(data+slot[-(i-1)].offset),
						slot[-(i-1)].length, (nodetype)type);
				left = 1;
				return true;
			}
			else {
				pageNo = getLeftLink();
				return true;
			}
		}
	}

	left = 0;
	get_key_data(NULL, (Datatype *) &pageNo,
			(KeyDataEntry *)(data+slot[0].offset),
			slot[0].length, (nodetype)type);

	return true;
}
Esempio n. 2
0
/* read line coordinates */
void read_coor(FILE * fp, SYMBEL * e)
{
    char buf[501];
    double x, y;

    G_debug(5, "    read_coor()");

    while (G_getl2(buf, 500, fp) != 0) {
	G_chop(buf);

	/* skip empty and comment lines */
	if ((buf[0] == '#') || (buf[0] == '\0'))
	    continue;

	get_key_data(buf);

	if (strcmp(key, "END") == 0) {
	    G_debug(5, "    LINE END");
	    return;
	}

	if (sscanf(buf, "%lf %lf", &x, &y) != 2) {
	    G_warning(_("Cannot read symbol line coordinates: %s"), buf);
	    return;
	}
	G_debug(5, "      x = %f y = %f", x, y);
	add_point(e, x, y);
    }
}
Esempio n. 3
0
void main(void)
{  
		cj_init();
		gq_init(); 
		led_init();
		key_init();
		wlw_init();
	
		while(1)
		{		
				if(key4==1)
				{
						cj_run();
						get_gq_data();
						led_body10cm();
						led_body20cm();
				}
				else
				{
						get_wlw_data();
						get_key_data();
						led_kongzhi();
						delayms(10);		//10MS
				}
		}
}              
Esempio n. 4
0
bool
cql::cql_map_impl_t::get_key_string(size_t i,
                                    std::string& output) const
{
    cql_byte_t* data = 0;
    cql_short_t size = 0;
    if (get_key_data(i, &data, size)) {
        output.assign(data, data + size);
        return true;
    }
    return false;
}
Esempio n. 5
0
Status BTIndexPage::get_next(RID& rid, void *key, PageId & pageNo)
{
	rid.slotNo++;

	if (rid.slotNo >= slotCnt)
	{
		pageNo = INVALID_PAGE;
		return NOMORERECS;
	}

	get_key_data(key, (Datatype *) &pageNo,
			(KeyDataEntry *)(data+slot[-rid.slotNo].offset),
			slot[-rid.slotNo].length,
			(nodetype)type);

	return OK;
}
Esempio n. 6
0
Status BTIndexPage::get_page_no(const void *key,
		AttrType key_type,
		PageId & pageNo)
{
	int i;
	for (i=slotCnt-1; i >= 0; i--) {
		if (keyCompare(key, (void*)(data+slot[-i].offset), key_type) >= 0)
		{
			get_key_data(NULL, (Datatype *) &pageNo,
					(KeyDataEntry *)(data+slot[-i].offset),
					slot[-i].length, (nodetype)type);
			return OK;
		}
	}

	pageNo = getPrevPage();
	return OK;
}
Esempio n. 7
0
Status BTIndexPage::get_first(RID& rid,
		void *key,
		PageId & pageNo)
{
	if (slotCnt == 0) {
		pageNo = INVALID_PAGE;
		return NOMORERECS;
	}

	rid.pageNo = curPage;
	rid.slotNo = 0; // begin with first slot

	get_key_data(key, (Datatype *) &pageNo,
			(KeyDataEntry *)(data+slot[0].offset), slot[0].length,
			(nodetype)type);

	return OK;
}
Esempio n. 8
0
static int find_first_key(uint64_t key)
{
  index_first = -1;
  index_count = 0;
  index_weight_count = 0;
  index_best = -1;
  index_rand = -1;

  ssize_t start = 0;
  ssize_t end = keycount;

  do {
    ssize_t mid = (end + start) / 2;

    if (from_be_u64(polyhash[mid].key) < key)
      start = mid;
    else {
      if (from_be_u64(polyhash[mid].key) > key)
        end = mid;
      else {
        start = max(mid - 4, 0);
        end = min(mid + 4, keycount);
      }
    }
  } while (end - start > 8);

  for (ssize_t i = start; i < end; i++)
    if (key == from_be_u64(polyhash[i].key)) {
      index_first = i;
      while (   index_first > 0
             && key == from_be_u64(polyhash[index_first - 1].key))
        index_first--;
      return get_key_data();
    }

  return -1;
}
Esempio n. 9
0
/* 
 *  Read symbol specified by name.
 *  Name: group/name | group/name@mapset 
 *        (later add syntax to prefer symbol from GISBASE)
 *  S_read() searches first in mapsets (standard GRASS search) and
 *   then in GISBASE/etc/symbol/ 
 */
SYMBOL *S_read(const char *sname)
{
    int i, j, k, l;
    FILE *fp;
    char group[500], name[500], buf[2001];
    const char *ms;
    char *c;
    double x, y, x2, y2, rad, ang1, ang2;
    int r, g, b;
    double fr, fg, fb;
    int ret;
    char clock;
    SYMBOL *symb;
    int current;		/* current part_type */
    SYMBPART *part;		/* current part */
    SYMBCHAIN *chain;		/* current chain */
    SYMBEL *elem;		/* current element */

    G_debug(3, "S_read(): sname = %s", sname);

    /* Find file */
    /* Get group and name */
    strcpy(group, sname);
    c = strchr(group, '/');
    if (c == NULL) {
	G_warning(_("Incorrect symbol name: '%s' (should be: group/name or group/name@mapset)"),
		  sname);
	return NULL;
    }
    c[0] = '\0';

    c++;
    strcpy(name, c);

    G_debug(3, "  group: '%s' name: '%s'", group, name);

    /* Search in mapsets */
    sprintf(buf, "symbol/%s", group);
    ms = G_find_file(buf, name, NULL);

    if (ms != NULL) {		/* Found in mapsets */
	fp = G_fopen_old(buf, name, ms);
    }
    else {			/* Search in GISBASE */
	sprintf(buf, "%s/etc/symbol/%s", G_gisbase(), sname);
	fp = fopen(buf, "r");
    }

    if (fp == NULL) {
	G_warning(_("Cannot find/open symbol: '%s'"), sname);
	return NULL;
    }

    /* create new symbol */
    symb = new_symbol();

    current = OBJ_NONE;		/* no part */

    /* read file */
    while (G_getl2(buf, 2000, fp) != 0) {
	G_chop(buf);
	G_debug(3, "  BUF: [%s]", buf);

	/* skip empty and comment lines */
	if ((buf[0] == '#') || (buf[0] == '\0'))
	    continue;

	get_key_data(buf);

	if (strcmp(key, "VERSION") == 0) {
	    if (strcmp(data, "1.0") != 0) {
		sprintf(buf, "Wrong symbol version: '%s'", data);
		return (err(fp, symb, buf));
	    }
	}
	else if (strcmp(key, "BOX") == 0) {
	    if (sscanf(data, "%lf %lf %lf %lf", &x, &y, &x2, &y2) != 4) {
		sprintf(buf, "Incorrect box definition: '%s'", data);
		return (err(fp, symb, buf));
	    }
	    symb->xscale = 1 / (x2 - x);
	    symb->yscale = 1 / (y2 - y);
	    if (x2 - x > y2 - y) {
		symb->scale = symb->xscale;
	    }
	    else {
		symb->scale = symb->yscale;
	    }
	}
	else if (strcmp(key, "STRING") == 0) {
	    G_debug(4, "  STRING >");
	    current = OBJ_STRING;
	    part = new_part(S_STRING);
	    add_part(symb, part);

	    chain = new_chain();
	    add_chain(part, chain);
	}
	else if (strcmp(key, "POLYGON") == 0) {
	    G_debug(4, "  POLYGON >");
	    current = OBJ_POLYGON;
	    part = new_part(S_POLYGON);
	    add_part(symb, part);

	}
	else if (strcmp(key, "RING") == 0) {
	    G_debug(4, "  RING >");
	    current = OBJ_RING;
	    chain = new_chain();
	    add_chain(part, chain);

	}
	else if (strcmp(key, "LINE") == 0) {
	    G_debug(4, "    LINE >");
	    elem = new_line();
	    add_element(chain, elem);
	    read_coor(fp, elem);

	}
	else if (strcmp(key, "ARC") == 0) {
	    G_debug(4, "    ARC");
	    ret =
		sscanf(data, "%lf %lf %lf %lf %lf %c", &x, &y, &rad, &ang1,
		       &ang2, &clock);
	    if (ret < 5) {
		sprintf(buf, "Incorrect arc definition: '%s'", buf);
		return (err(fp, symb, buf));
	    }
	    if (ret == 6 && (clock == 'c' || clock == 'C'))
		i = 1;
	    else
		i = 0;
	    elem = new_arc(x, y, rad, ang1, ang2, i);
	    add_element(chain, elem);

	}
	else if (strcmp(key, "END") == 0) {
	    switch (current) {
	    case OBJ_STRING:
		G_debug(4, "  STRING END");
		current = OBJ_NONE;
		break;
	    case OBJ_POLYGON:
		G_debug(4, "  POLYGON END");
		current = OBJ_NONE;
		break;
	    case OBJ_RING:
		G_debug(4, "  RING END");
		current = OBJ_POLYGON;
		break;
	    }
	}
	else if (strcmp(key, "COLOR") == 0) {
	    if (G_strcasecmp(data, "NONE") == 0) {
		part->color.color = S_COL_NONE;
	    }
	    else if (sscanf(data, "%d %d %d", &r, &g, &b) == 3) {
		if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255)
		    G_warning(_("Incorrect symbol color: '%s', using default."),
			      buf);
		else {
		    fr = r / 255.0;
		    fg = g / 255.0;
		    fb = b / 255.0;
		    part->color.color = S_COL_DEFINED;
		    part->color.r = r;
		    part->color.g = g;
		    part->color.b = b;
		    part->color.fr = fr;
		    part->color.fg = fg;
		    part->color.fb = fb;
		    G_debug(4, "  color [%d %d %d] = [%.3f %.3f %.3f]", r, g,
			    b, fr, fg, fb);
		}
	    }
	    else {
		G_warning(_("Incorrect symbol color: '%s', using default."),
			  buf);
	    }
	}
	else if (strcmp(key, "FCOLOR") == 0) {
	    if (G_strcasecmp(data, "NONE") == 0) {
		part->fcolor.color = S_COL_NONE;
	    }
	    else if (sscanf(data, "%d %d %d", &r, &g, &b) == 3) {
		if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255)
		    G_warning(_("Incorrect symbol color: '%s', using default."),
			      buf);
		else {
		    fr = r / 255.0;
		    fg = g / 255.0;
		    fb = b / 255.0;
		    part->fcolor.color = S_COL_DEFINED;
		    part->fcolor.r = r;
		    part->fcolor.g = g;
		    part->fcolor.b = b;
		    part->fcolor.fr = fr;
		    part->fcolor.fg = fg;
		    part->fcolor.fb = fb;
		    G_debug(4, "  color [%d %d %d] = [%.3f %.3f %.3f]", r, g,
			    b, fr, fg, fb);
		}
	    }
	    else {
		G_warning(_("Incorrect symbol color: '%s', using default."),
			  buf);
	    }
	}
	else {
	    sprintf(buf, "Unknown keyword in symbol: '%s'", buf);
	    return (err(fp, symb, buf));
	    break;
	}
    }

    /* Debug output */

    G_debug(3, "Number of parts: %d", symb->count);
    for (i = 0; i < symb->count; i++) {
	part = symb->part[i];
	G_debug(4, "  Part %d: type: %d number of chains: %d", i, part->type,
		part->count);
	G_debug(4, "           color: %d: fcolor: %d", part->color.color,
		part->fcolor.color);
	for (j = 0; j < part->count; j++) {
	    chain = part->chain[j];
	    G_debug(4, "    Chain %d: number of elements: %d", j,
		    chain->count);
	    for (k = 0; k < chain->count; k++) {
		elem = chain->elem[k];
		G_debug(4, "      Element %d: type: %d", k, elem->type);
		if (elem->type == S_LINE) {
		    G_debug(4, "        Number of points %d",
			    elem->coor.line.count);
		    for (l = 0; l < elem->coor.line.count; l++) {
			G_debug(4, "        x, y: %f %f",
				elem->coor.line.x[l], elem->coor.line.y[l]);
		    }
		}
		else {
		    G_debug(4, "        arc r = %f", elem->coor.arc.r);
		}
	    }
	}
    }

    fclose(fp);

    return symb;
}
Esempio n. 10
0
bool BTIndexPage::redistribute(BTIndexPage *pptr, BTIndexPage *parentPtr,
		AttrType key_type, int left, const void *deletedKey)
{
	// assertion: pptr and parentPtr are  pinned

	if (left) { // 'this' is the left sibling of pptr
		if (slot[-(slotCnt-1)].length + free_space() > (MAX_SPACE-DPFIXED)/2) {
			// cannot spare a record for its underflow sibling
			return false;
		}
		else {
			// get its sibling's first record's key
			Status st;
			RID dummyRid;
			PageId dummyPageId;
			Keytype oldKey;
			pptr->get_first(dummyRid, (void*)&oldKey, dummyPageId);

			// get the entry pointing to the right sibling
			Keytype entry;
			st = parentPtr->findKey((void*)&oldKey, (void*)&entry, key_type);
			assert(st == OK);

			// get the leftmost child pointer of the right sibling
			PageId leftMostPageId = pptr->getLeftLink();

			// insert  <entry,leftMostPageId>  to its sibling
			st = pptr->insertKey((void*)&entry, key_type,
					leftMostPageId, dummyRid);
			if (st != OK)
				return false;

			// get the last record of itself
			PageId lastPageId;
			Keytype lastKey;
			get_key_data(&lastKey, (Datatype*)&lastPageId,
					(KeyDataEntry*)(data+slot[-(slotCnt-1)].offset),
					slot[-(slotCnt-1)].length, (nodetype)type);

			// set sibling's leftmostchild to be lastPageId
			pptr->setLeftLink(lastPageId);

			// delete the last record from the old page
			RID delRid;
			delRid.pageNo = page_no();
			delRid.slotNo = slotCnt-1;
			st = deleteRecord(delRid);
			assert(st == OK);

			// adjust the entry pointing to sibling in its parent
			if (deletedKey)
				st = parentPtr->adjust_key((void*)&lastKey, deletedKey,
						key_type);
			else
				st = parentPtr->adjust_key((void*)&lastKey,
						(void*)&oldKey, key_type);
			assert (st == OK);
		}
	}
	else { // 'this' is the right sibling of pptr
		if (slot[0].length + free_space() > (MAX_SPACE-DPFIXED)/2) {
			// cannot spare a record for its underflow sibling
			return false;
		}
		else {
			// get the first record
			Status st;
			PageId firstPageId;
			Keytype firstKey;
			get_key_data(&firstKey, (Datatype*)&firstPageId,
					(KeyDataEntry*)(data+slot[0].offset),
					slot[0].length, (nodetype)type);

			// get its leftmost child pointer
			PageId leftMostPageId = getLeftLink();

			// get the entry in its parent pointing to itself
			Keytype entry;
			st = parentPtr->findKey((void*)&firstKey, (void*)&entry, key_type);
			assert(st == OK);

			// insert <entry, leftMostPageId> to its left sibling
			RID dummyRid;
			st = pptr->insertKey((void*)&entry, key_type,
					leftMostPageId, dummyRid);
			if (st != OK)
				return false;

			// set its new leftmostchild
			setLeftLink(firstPageId);

			// delete the first record
			RID delRid;
			delRid.pageNo = page_no();
			delRid.slotNo = 0;
			st = deleteRecord(delRid);
			assert(st == OK);

			// adjust the entry pointing to itself in its parent
			st = parentPtr->adjust_key((void*)&firstKey,
					(void*)&entry, key_type);
			assert(st == OK);
		}
	}

	return true;
}