Beispiel #1
0
 bool PptvMedia::parse_video_param(
     Video & video, 
     std::string const & param)
 {
     boost::system::error_code ec;
     ec 
         || (ec = map_find(param, "name", video.name, "&"))
         || (ec = map_find(param, "bitrate", video.bitrate, "&"))
         || (ec = map_find(param, "duration", video.duration, "&"));
     return !ec;
 }
Beispiel #2
0
 bool PptvMedia::parse_jump_param(
     Jump & jump, 
     std::string const & param)
 {
     boost::system::error_code ec;
     ec 
         || (ec = map_find(param, "svrhost", jump.server_host, "&"))
         || (ec = map_find(param, "svrtime", jump.server_time, "&"))
         || (ec = map_find(param, "bakhost", jump.back_host, "&"))
         || (ec = map_find(param, "bwtype", jump.bw_type, "&"));
     return !ec;
 }
Beispiel #3
0
/*
 * Finds node in the map.
 * 
 * @author Lukasz Koprowski <*****@*****.**>
 * @return Either node ot a parent it'd have.
 */
snode * map_find(snode * root, long long int key){
    if (root == NULL ) {
		return NULL;
	} else if (root -> key == key || root -> key == EMPTY_KEY) {
		return root;
	} else if (root -> key > key) {
	    if(root -> right == NULL) return root;
		return map_find(root -> right, key);
	} else {
	    if(root -> left == NULL) return root;
		return map_find(root -> left, key);
	}
}
Beispiel #4
0
int main()
{
	int i;

	map_init();

	map_insert("nihao",1);
	map_insert("nishi",2);
	map_insert("nishi",3);
	map_delete("nishi");
	printf("%d %d\n",map_find("nishi"),map_find("nihao"));
	printf("\n");
	return 0;
}
Beispiel #5
0
void sys_seek(int fd, unsigned position)
{
    struct file* file = map_find(get_filemap(), fd);

    if (file != NULL && position <= (unsigned)sys_filesize(fd))
        file_seek(file, position);
}
Beispiel #6
0
static int
header(gpt_t gpt)
{
	unsigned int revision;
	map_t map;
	struct gpt_hdr *hdr;
	char buf[128];

	gpt_show_num("Media Size", (uintmax_t)gpt->mediasz);
	printf("Sector Size: %u\n", gpt->secsz);

	gpt_show_num("Number of Sectors",
	    (uintmax_t)(gpt->mediasz / gpt->secsz));

	printf("\nHeader Information:\n");

	map = map_find(gpt, MAP_TYPE_PRI_GPT_HDR);
	if (map == NULL) {
		printf("- GPT Header not found\n");
		return 0;
	}

	hdr = map->map_data;
	revision = le32toh(hdr->hdr_revision);
	printf("- GPT Header Revision: %u.%u\n", revision >> 16,
	     revision & 0xffff);
	gpt_show_num("- First Data Sector", hdr->hdr_lba_start);
	gpt_show_num("- Last Data Sector", hdr->hdr_lba_end);
	gpt_uuid_snprintf(buf, sizeof(buf), "%d", hdr->hdr_guid);
	printf("- Media GUID: %s\n", buf);
	printf("- Number of GPT Entries: %u\n", hdr->hdr_entries);
	return 0;
}
Beispiel #7
0
Symbol * Env_get_prot(Env * env, char * id) {
    void * found;
    for (; env != NULL; env = env->prev) 
        if (( found = map_find(&env->prot_table, id) ) != NULL)
            return *((Symbol **) found);
    return NULL;
}
Beispiel #8
0
/* 
 * Insert symbol into environment. If the symbol is already in the environment,
 * return 0. Otherwise, insert it and return 1
 */
int Env_put(Env * env, char * id, Symbol * sym) {
    if (map_find(&env->table, id) != NULL)
        return 0;

    if (sym->type != TYPE_FN)
        if (map_find(&env->prot_table, id) != NULL)
            return 0;

    //sym->scope = env;

    if (sym->type == TYPE_FN_PROT)
        map_insert(&env->prot_table, id, sym);
    else
        map_insert(&env->table, id, sym);
    return 1;
}
Beispiel #9
0
static obj_ptr _map_find(obj_ptr args, obj_ptr env)
{
    int     ct = _length(args);
    obj_ptr map, key, res;

    if (ct < 2 || ct > 3)
        return MKERROR_STRING(MKSTRING("Syntax: (map-find map key [default])"));

    map = CAR(args);
    if (NMAPP(map))
        return MKERROR(MKSTRING("Expected a map in first arg to map-find"), map);


    key = CADR(args);

    res = map_find(&MAP(map), key);
    if (!res)
    {
        if (ct == 3)
            return CADDR(args);
        else
            return MKERROR(MKSTRING("Key not found."), key);
    }

    return res;
}
Beispiel #10
0
void plist_set_exit_status(struct map* m, key_t k, int status)
{
  lock_acquire(&plist_lock);
  struct process* p = map_find(m, k);
  p->exit_status = status;
  lock_release(&plist_lock);
}
Beispiel #11
0
struct process* plist_find_process(struct map* m, key_t k)
{
  lock_acquire(&plist_lock);
  struct process* p = map_find(m, k);
  lock_release(&plist_lock);
  return p;
}
Beispiel #12
0
void ProgramProfiler::log_stats(const std::map<const void *, size_t> &linenos) {
    std::unique_lock<std::mutex> lock(s_mutex);
    for (ProgramProfiler *instance : s_instances) {
        instance->unsafe_report();
    }

    std::vector<LogLine> log_lines;
    double total_sec = 0;
    for (auto &pair : s_stats) {
        size_t lineno = map_find(linenos, pair.first);
        Stat &stat = pair.second;
        log_lines.push_back({stat, lineno});
        total_sec += stat.time * 1e-6;
        stat.count = 0;
        stat.time = 0;
    }
    std::sort(log_lines.begin(), log_lines.end());

    POMAGMA_INFO("Profile of VirtualMachine programs:");
    POMAGMA_INFO(" Line       Calls Percent   Total sec Per call sec");
    POMAGMA_INFO("----- ----------- ------- ----------- ------------");
    for (const auto &line : log_lines) {
        double time_sec = line.stat.time * 1e-6;
        double percent = 100 * time_sec / total_sec;
        POMAGMA_INFO(std::fixed << std::setprecision(2) << std::setw(5)
                                << std::right << line.lineno << std::setw(12)
                                << std::right << line.stat.count << std::setw(8)
                                << std::right << percent << std::setw(12)
                                << time_sec << std::setw(10)
                                << (time_sec / line.stat.count));
    }
}
Beispiel #13
0
/*
  A function that given an integer (obtained from above function)
  and a process id FIND the file in a list. Should return NULL if
  the specified process did not insert the file or already removed
  it.
*/
value_t flist_find_file(int fd, struct thread* t)
{

  value_t v = map_find(&(t->open_files), fd);

  return v;
}
Beispiel #14
0
static task_t *tasks_find(task_id tid) {
  task_t f = { tid };
  lc_spin_lock(lock);
  task_t *t = map_find(tasks, &f);
  lc_spin_unlock(lock);
  return t;
}
Beispiel #15
0
static void add_depend(const char *source, set_t *incl, map_t *deps)
{
    set_t *mydeps;
    llnode_t *tmp;
    int i,num;

    if (source == NULL) return;

    mydeps = map_find(deps,source);
    if (mydeps != NULL) {
        num = mydeps->nbuckets;

        for (i = 0; i < num; ++i) {
            tmp = mydeps->buckets + i;
            while (tmp->next != NULL) {
                if (set_find(incl,tmp->key) == 0) {
                    set_add(incl,tmp->key);
                    add_depend(tmp->key,incl,deps);
                }
                tmp = tmp->next;
            }
        }
    }

}
Beispiel #16
0
void *map_get_ref(map *m, char *key)
{
    int idx = map_find(m, key);
    if(idx < 0)
        return NULL;
    return &m->values[idx];
}
Beispiel #17
0
static inline int __search_avp_map(str *alias, map_t m)
{
	int **id = (int **)map_find(m, *alias);
	LM_DBG("looking for [%.*s] avp %s - found %d\n", alias->len, alias->s,
			m == avp_map_shm ? "in shm": "", id ? p2int(*id) : -1);
	return id ? p2int(*id) : -1;
}
Beispiel #18
0
/**
 * Skriver till fd (skärm eller fil)
 * Returnerar antalet skrivna tecken eller -1 om antalet tecken som ska skrivas
 * är 0 eller om filen inte finns.
 */
int sys_write(int fd, const void* buffer, unsigned length)
{
    if (fd == STDIN_FILENO) // Vi kan inte skriva till tangentbordet
    {
        return -1;
    }

    if (fd == STDOUT_FILENO) // skärmen
    {
        putbuf(buffer, length);
        return length;
    }
    else
    {
        // Skriva till fil
        struct file* write_to = map_find(get_filemap(), fd);
        if(write_to != NULL)
        {
            // Skriver buffer till write_to. Returnerar antalet skrivna tecken
            // Kan returnera ett antal tecken < length om filen är för liten
            return file_write(write_to, buffer, length);
        }
        else
        {
            return -1; // Filen finns inte, eller så ville vi skriva 0 tecken.
        }
    }
    // Hit ska vi inte komma!
}
Beispiel #19
0
/*
 * Inserts element into the map.
 * 
 * @author Lukasz Koprowski <*****@*****.**>
 */
int map_put(snode * root, char * key, int value) {
    if(key[0] == '\0') return SUCCESS;

	snode * node = malloc(sizeof(snode));
	if(node == NULL){
	    error(ERR_NOT_ENOUGH_MEMORY);
	}

	node -> key = get_hashcode(key);
	node -> value = value;
	node -> left = NULL;
	node -> right = NULL;

	snode * fnode = map_find(root, node -> key);
	
	if (fnode -> key == EMPTY_KEY) {
		fnode -> key = node -> key;
		fnode -> value = node -> value;
		free(node);
	} else if (fnode -> key > node -> key) {
		fnode -> right = node;
	} else {
		fnode -> left = node;
	}
	
	return SUCCESS;
}
Beispiel #20
0
void map_del(struct map_t* map, const char* key)
{
    struct map_find_results_t find_results = map_find(map, key);

    if (!find_results.exact_match) {
        return;
    }

    struct map_node_t* node = find_results.node;

    if (map->free_func && node->value) {
        (*map->free_func)(node->value);
    }

    if (node == map->head) {
        map->head = map->head->next;
    } else {
        find_results.prev_node->next = node->next;
    }

    free(node->key);
    free(node);

    map->size--;
}
Beispiel #21
0
void tech_free(void* ptr)
{
	phashnode_t node;

	node = map_find(memory, ptr);
	assert (node);
	FreeMem(ptr, (uint32)node->value);
}
Beispiel #22
0
unsigned sys_tell (int fd)
{
    struct file* file = map_find(get_filemap(), fd);

    if (file != NULL)
        return file_tell(file);

    return -1;
}
Beispiel #23
0
int sys_filesize(int fd)
{
    struct file* file = map_find(get_filemap(), fd);

    if (file != NULL)
        return file_length(file);

    return -1;
}
Beispiel #24
0
void map_rm(map *m, char *key, void (*destroy_callback)(void*))
{
    int idx = map_find(m, key);
    if(idx < 0)
        return;

    list_rm_at(idx, &m->keys, &free);
    list_rm_at(idx, &m->values, destroy_callback);
}
Beispiel #25
0
void sys_close(int fd)
{
    struct file* close_file = map_find(get_filemap(), fd);

    if(close_file != NULL)
    {
        filesys_close(close_file);
        map_remove(get_filemap(), fd); // important to remove from file hEHE
    }
}
Beispiel #26
0
int_str_t *kv_get(map_t _store, const str* _key)
{
	int_str_t **val;

	val = (int_str_t **)map_find(_store, *_key);
	if (val)
		return *val;

	return NULL;
}
Beispiel #27
0
static struct auth_profile *get_profile_by_name(char *uname)
{

	int i;

	i=map_find(uname);

	if (i==MAP_NOT_FOUND) return 0;
	else return (struct auth_profile *)i;
}
Beispiel #28
0
void* map_get(struct map_t* map, const char* key)
{
    const struct map_find_results_t find_result = map_find(map, key);

    if (find_result.exact_match) {
        return find_result.node->value;
    }

    return NULL;
}
void va_attribute_count_add( int size, int count, container *attributes, int argc, va_list *ap )
{
    ant[0]++;
    int		i;
    char	*id = va_arg(*ap, char*);
    container	*subattr;

    iterator	it = map_find(attributes, id);
    if (it.valid)
	{
	    ant[1]++;
	    subattr = pair(map_val(it)).first.ptr;

	    container	*M = pair(map_val(it)).second.ptr;
	    it = map_find(M, count);
	    if (it.valid)
		{
		    ant[2]++;
		    map_val(it).i+= size;
		}
	    else
		{
		    ant[3]++;
		    map_insert(M, count, size);
		}
	    //for (i=0; i<len; i++)
		//((int*)pair(map_val(it)).second.ptr)[i]+= count[i];
	}
    else
	{
	    ant[4]++;
	    subattr = map_container( string_container(), pair_container( ptr_container(), ptr_container() ) );

	    container	*M = map_container( int_container(), int_container() );
	    map_insert(M, count, size);
	    //int		*C = malloc(sizeof(int)*len);
	    //for (i=0; i<len; i++) C[i] = count[i];
	    map_insert(attributes, id, subattr, M);
	}

    if (argc > 1) va_attribute_count_add( size, count, subattr, argc-1, ap );
}
Beispiel #30
0
task_t *task_ref(task_id tid) {
  task_t f = { tid };
  lc_spin_lock(lock);
  task_t *t = map_find(tasks, &f);
  if (t) {
    atomic_int_inc(&t->ref_count);
  }
  lc_spin_unlock(lock);

  return t;
}