<commit_before>#include "leda.h"
#include "stage.h"
#include "lf_hash.h"

#ifdef DEBUG
//can be found here  http://www.lua.org/pil/24.2.3.html
void stackDump (lua_State *L, const char *text) {
      int i;
      int top = lua_gettop(L);
	  if (text == NULL)
		printf("--------Start Dump------------\n");
	  else
	    printf("--------Start %s------------\n", text);
      for (i = 1; i <= top; i++) {  /* repeat for each level */
        int t = lua_type(L, i);
        switch (t) {
    
          case LUA_TSTRING:  /* strings */
            printf("`%s'", lua_tostring(L, i));
            break;
    
          case LUA_TBOOLEAN:  /* booleans */
            printf(lua_toboolean(L, i) ? "true" : "false");
            break;
    
          case LUA_TNUMBER:  /* numbers */
            printf("%g", lua_tonumber(L, i));
            break;
    
          default:  /* other values */
            printf("%s", lua_typename(L, t));
            break;
    
        }
        printf("  ");  /* put a separator */
      }
      printf("\n");  /* end the listing */
	  printf("--------End Dump------------\n");
    }

void tableDump(lua_State *L, int idx, const char* text)
{
	lua_pushvalue(L, idx);		// copy target table
	lua_pushnil(L);
	  if (text == NULL)
		printf("--------Table Dump------------\n");
	  else
	    printf("--------Table dump: %s------------\n", text);
	while (lua_next(L,-2) != 0) {
		printf("%s - %s\n",
			lua_typename(L, lua_type(L, -2)),
			lua_typename(L, lua_type(L, -1)));
		lua_pop(L, 1);
	}
	lua_pop(L, 1);	// remove table copy
    printf("--------End Table dump------------\n");
}
#endif

static qt_hash H;

static int leda_getstage(lua_State * L) {
	size_t len=0; 
	const void ** key=(const void **)lua_tolstring(L,1,&len);
	if(len!=sizeof(void *)) {
		lua_pushnil(L);
		lua_pushliteral(L,"Key length error");
		return 2;
	}
	stage_t s=qt_hash_get(H,*key);
	if(s) {
		leda_buildstage(L,s);
		return 1;
	}
	lua_pushnil(L);
	lua_pushliteral(L,"Stage not found");
	return 2;
}


static int leda_addstage(lua_State * L) {
   stage_t s=leda_pushstage(L,1);
	qt_hash_put(H,s,s);
	return 0;
}

static const struct luaL_Reg LuaExportFunctions[] = {
	{"stage_new",leda_newstage},
	{"stage_get",leda_getstage},
	{"stage_add",leda_addstage},
	{NULL,NULL}
};

LEDA_EXPORTAPI	int luaopen_leda_scheduler(lua_State *L){	
	// Export Lua API
	H=qt_hash_create(0);<commit_msg>Initializing global lockfree hashtable<commit_after>#include "leda.h"
#include "stage.h"
#include "lf_hash.h"

#ifdef DEBUG
//can be found here  http://www.lua.org/pil/24.2.3.html
void stackDump (lua_State *L, const char *text) {
      int i;
      int top = lua_gettop(L);
	  if (text == NULL)
		printf("--------Start Dump------------\n");
	  else
	    printf("--------Start %s------------\n", text);
      for (i = 1; i <= top; i++) {  /* repeat for each level */
        int t = lua_type(L, i);
        switch (t) {
    
          case LUA_TSTRING:  /* strings */
            printf("`%s'", lua_tostring(L, i));
            break;
    
          case LUA_TBOOLEAN:  /* booleans */
            printf(lua_toboolean(L, i) ? "true" : "false");
            break;
    
          case LUA_TNUMBER:  /* numbers */
            printf("%g", lua_tonumber(L, i));
            break;
    
          default:  /* other values */
            printf("%s", lua_typename(L, t));
            break;
    
        }
        printf("  ");  /* put a separator */
      }
      printf("\n");  /* end the listing */
	  printf("--------End Dump------------\n");
    }

void tableDump(lua_State *L, int idx, const char* text)
{
	lua_pushvalue(L, idx);		// copy target table
	lua_pushnil(L);
	  if (text == NULL)
		printf("--------Table Dump------------\n");
	  else
	    printf("--------Table dump: %s------------\n", text);
	while (lua_next(L,-2) != 0) {
		printf("%s - %s\n",
			lua_typename(L, lua_type(L, -2)),
			lua_typename(L, lua_type(L, -1)));
		lua_pop(L, 1);
	}
	lua_pop(L, 1);	// remove table copy
    printf("--------End Table dump------------\n");
}
#endif

static qt_hash H=NULL;

static int leda_getstage(lua_State * L) {
	size_t len=0; 
	const void ** key=(const void **)lua_tolstring(L,1,&len);
	if(len!=sizeof(void *)) {
		lua_pushnil(L);
		lua_pushliteral(L,"Key length error");
		return 2;
	}
	stage_t s=qt_hash_get(H,*key);
	if(s) {
		leda_buildstage(L,s);
		return 1;
	}
	lua_pushnil(L);
	lua_pushliteral(L,"Stage not found");
	return 2;
}


static int leda_addstage(lua_State * L) {
   stage_t s=leda_pushstage(L,1);
	qt_hash_put(H,s,s);
	return 0;
}

static const struct luaL_Reg LuaExportFunctions[] = {
	{"stage_new",leda_newstage},
	{"stage_get",leda_getstage},
	{"stage_add",leda_addstage},
	{NULL,NULL}
};

LEDA_EXPORTAPI	int luaopen_leda_scheduler(lua_State *L){	
	// Export Lua API
	if(!H) H=qt_hash_create(0);
{'fraction_non_alphanumeric': 0.20945242556735374, 'fraction_numerical': 0.007911721840516344, 'mean_word_length': 2.2437542201215397, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1245676', 'n_tokens_mistral': 1886, 'n_tokens_neox': 1800, 'n_words': 391}